Android stereo car and arduino

I did the transfert of data between arduino and an android device using bluetooth and it workd good.

When I switched to usb cable to transfer data , a problem of connection appears ,

The led of rxd is on , the tx is off

I used the usb ttl converter and i enabled the debug usb in android device

The apps that i installed in android doesn t send data

I UPDATED the baud to 9600 and receiving the correct values sent by arduino

Your ReadSerial block came back with an empty text, and you tried to take segment of position 1 of it without making sure there was a position 1.

Just like you tested length(input)> 1 in the next block, you must first test
length(input) > 0 before taking a segment of input.

The text segment block is very fussy about its input.

Look for the place where you multiply, and don't allow empty text as input to it.


Can some one fix that .... :neutral_face:

My arduino code

I confess I have not used the AI2 serial component yet.

I have seen posts by other users on this board that have.

However, I have some questions for you that might help you:

  • Does the serial component have a Delimiter setting like the BlueTooth Client component, to help deliver only complete (println()) messages? If not, does your code have to look for \n in the incoming text?
  • Do you initialize before or after setting baud rate?
  • What is the difference between opening and initializing? Do you need to do both, and in any particular order?
1 Like

I gave up and came back to bluetooth :face_with_head_bandage:
I have to learn more about the basics of usb serial communications

I had a look at your .aia. I found 2 basic problems. You have to call open after initialize. You changed to SerialOTG in screen init, but your buttons still used the built in Serial. That's why you got the error "not initialized"

My advice to you if you want to learn more on using serial communication are:
Search the forum for “serial”.
If you want to use SerialOTG, read the documentation and take a close look at the example app:s

Good luck!

1 Like

An other question : if an Android head unit contains 2 USB ports ; how to switch between those two ports with OTG ?

First: I can see you are using an old version with the suffix “serial” in the names. This has been removed since it’s redundant, and only makes the names longer. See the documentation for the extension.
With this extension, it should be possible to use serial, BT or TCP/IP in the same way, except for timing.

BytesReceived>0 only indicates you have received 1 or more bytes. In BT you most of the time receives a block of data, in this case a complete message (But not always depending on the BT module).

If you have fixed length messages, wait until you received all characters. If you use a delimiter LF, use a later version of SerialOTG that implements such a message handling.

See: Appinventor-SerialOTG/SerialOTG_1.4.pdf at main · rkl099/Appinventor-SerialOTG · GitHub

1 Like

I don't know if you can, and I don't have such a device to test on.

There is no selection in the extension. I don't know how it works with an Android emulator.