Thank you for the good tutorial! Note to viewers that use this tutorial at a later time and targeting Android 12 or higher: Your app will crash if you set your PendingIntent flag to "0" in the startUsbConnecting() function. Instead use: val intent: PendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { PendingIntent.getBroadcast(this, 0, Intent(ACTION_USB_PERMISSION), FLAG_MUTABLE) } else { PendingIntent.getBroadcast(this, 0, Intent(ACTION_USB_PERMISSION), 0) }
Excellent video. But it only explains how to send data through the connected USB device. I would very much like for you to explain how to also receive data. Any clues on that?
To add Serial read: Add this callback: var mCallback = UsbReadCallback { data: ByteArray? -> val dataStr = data.toString() Log.i("Serial", "Data received: " + dataStr) } And add this line: m_serial!!.read(mCallback) after this line: m_serial!!.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF)
I am new at this but, this appears to only receive one byte from the serial port, what if we are trying to receive 8195 bytes at a time. What about len = m_serial!!.read(buf , timeout) how do we implement that? Adding a read operation has been a challenge. BTW - Thank you for this video it's been a great help. For sending one byte I think this works also, m_serial!!.write("0x50".toByteArray()). I struggled with getting a 1 byte Array to work.
Hi, I recently have been following this tutorial series. It has proven very helpful, but how can I verify that I am opening the right port. Such as ttyl1 or ttyl3 serial ports from my device. Also how can I verify that I am sending data such as sending a simple "Hello World" from my device to my serial console on my PC? Thanks in advance!
So its been six months since it was posted that a read data video was in the works, but its still not posted. What is the hold up? Pretty useless with a read ability
Hello, could you please share the next steps? I followed instructions and have the app set up properly to connect and send data over USB, but send to what? How do I receive? Please show how you would set up something (like an arduino, for example) on the receiving end... thanks.
hey guys, it's as simple as this for reading: m_serial.read(readCallback) private val readCallback = UsbSerialInterface.UsbReadCallback { bytes -> val string = bytes.toString(Charsets.UTF_8) }
Hi JKevin, but where do I put thew. m_serial.read(readCallback) instruction? is the received data making an interruption or we need to poll for the data? thanks
Thanks for usefull information. I want to send serial data to PC instead of Arduino. When I use this code, PC is not recognized as attached device. Is there a way to implement what I am looking for. I would appriciate any help :)
I connected only laptop to phone. m_device is null also for me. How did you solve this if you solved it? I am thinking to use my usb Hard disk drive with usb converter from type C. Maybe I can see my hdd.
i am looking for someone to collaborate on a project. what we require is some expertise in getting an Arduino UNO board to communicate with a Android phone via USB (i.e. have the UNO trigger the Android to ring a stored number), not rocket science i know. the objective of the project is to have the UNO board monitor a series of vibration sensors, that bit has been sorted. when the vibe sens are tripped, the UNO communicates with the Android via USB and has it ring a stored number. its a cheep and cheerful bike alarm.
Thank you for the good tutorial! Note to viewers that use this tutorial at a later time and targeting Android 12 or higher: Your app will crash if you set your PendingIntent flag to "0" in the startUsbConnecting() function. Instead use:
val intent: PendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.getBroadcast(this, 0, Intent(ACTION_USB_PERMISSION),
FLAG_MUTABLE)
} else {
PendingIntent.getBroadcast(this, 0, Intent(ACTION_USB_PERMISSION),
0)
}
Very good videos. But please do a follow up video on how to read from serial.. Have been waiting a long time now... 🙂 Keep up the good work!! 👍👍👍
Yes, please!
Excellent video. But it only explains how to send data through the connected USB device. I would very much like for you to explain how to also receive data. Any clues on that?
Thank you for the tutorial, but how to read / write can bus protocol? Would be the same?
To add Serial read:
Add this callback:
var mCallback = UsbReadCallback { data: ByteArray? ->
val dataStr = data.toString()
Log.i("Serial", "Data received: " + dataStr)
}
And add this line:
m_serial!!.read(mCallback)
after this line:
m_serial!!.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF)
I am new at this but, this appears to only receive one byte from the serial port, what if we are trying to receive 8195 bytes at a time. What about len = m_serial!!.read(buf , timeout) how do we implement that? Adding a read operation has been a challenge. BTW - Thank you for this video it's been a great help. For sending one byte I think this works also, m_serial!!.write("0x50".toByteArray()). I struggled with getting a 1 byte Array to work.
Hi, I recently have been following this tutorial series. It has proven very helpful, but how can I verify that I am opening the right port. Such as ttyl1 or ttyl3 serial ports from my device. Also how can I verify that I am sending data such as sending a simple "Hello World" from my device to my serial console on my PC? Thanks in advance!
So its been six months since it was posted that a read data video was in the works, but its still not posted. What is the hold up? Pretty useless with a read ability
Please! Upload the serial read! Thanks a lot for the great work!
Hi Roberto, thanks for the comment. We have a tutorial for serial read in the pipeline and hope to have it released soon.
How About Serial Read It Possible?
Friend how do we receive a string from the arduino, thanks
Hello, could you please share the next steps? I followed instructions and have the app set up properly to connect and send data over USB, but send to what? How do I receive? Please show how you would set up something (like an arduino, for example) on the receiving end... thanks.
Great work
I have a different problem
How can i connect and read and write data using RS232 cable
Is there a way to speed up the rate at which the data sends? My Arduino seems to respond slowly to turning on and off.
is this library(USB Serial) work with java in android studio or just in Kotlin ??
hey guys, it's as simple as this for reading:
m_serial.read(readCallback)
private val readCallback = UsbSerialInterface.UsbReadCallback { bytes ->
val string = bytes.toString(Charsets.UTF_8)
}
Hi JKevin, but where do I put thew. m_serial.read(readCallback) instruction? is the received data making an interruption or we need to poll for the data?
thanks
does this library only work for Kotlin? or can you use Java also?
has anyone worked out how to do the read? the libary gives a java example I cant work out what the call back function should look in kotlin code
Is there a way to get kotlin to read and display a live video signal using this?
Thanks for usefull information. I want to send serial data to PC instead of Arduino. When I use this code, PC is not recognized as attached device. Is there a way to implement what I am looking for. I would appriciate any help :)
Hello Mustafa!
I have the same question. Did you solve it? How?
hi, same question. Is there any solving?
"private fun & private val" isnt working on my android studio any clues?
Hello, great work.. but i have a question.. How i can read data from USB?? Please help...
How i use the callback??
Thanks for the comment. We're planning to address exactly that in a forthcoming video. Stay tuned!
Hello, so when you think that can upload the read video?? Please hurry... :)
Hello, i need your help.. i cannot implement the read function.. can you help me please?? my email is: power_arox@hotmail.com... please please...
?@@prod.dinamo7206 have you done it
i am still confused why the m_device is null ,
how does it get instance of device to start connection from device list
I connected only laptop to phone. m_device is null also for me. How did you solve this if you solved it? I am thinking to use my usb Hard disk drive with usb converter from type C. Maybe I can see my hdd.
How do i make it communicate in hexadecimal
i am looking for someone to collaborate on a project. what we require is some expertise in getting an Arduino UNO board to communicate with a Android phone via USB (i.e. have the UNO trigger the Android to ring a stored number), not rocket science i know. the objective of the project is to have the UNO board monitor a series of vibration sensors, that bit has been sorted. when the vibe sens are tripped, the UNO communicates with the Android via USB and has it ring a stored number. its a cheep and cheerful bike alarm.
part 3?:)
What about read?
thank you
4:41 LOL
Stop it.