Serial OTG Port does not open Serial Port


I´m having problems communicating via OTG to a Arduino UNO.
That can I see is that the port can't initialize.
I´m using the extencion SerialOtg Extension Version: 1
Date Built: 2022-04-13.

I tested it with two Androids devices, one with Android 10 and the other with Android 11.
Any ideas?.


I need more information on what happens.
One thing, your block btn_open will always set Label1 to "not initialized" when the button is pressed.

Hi @rkl099 I modified the blocks, thanks a lot.
Now I can see that the problem is When I call the function Serial OTG1 Open, it returns "false". Can't open the serial port.

Do you use an original UNO?
Can you access the Arduino with a serial terminal?
Do you get a message to allow the app to use USB Serial the first time you press Open?

Try the following:

  1. Initialize SerialOTG without OTG cable connected.
  2. Connect the OTG cable to the phone.
  3. Click the open button. Now Android will ask for permission to use USB Serial.
  4. Grant permission.
  5. Click the Open button again. The port should now be open.

Depending on the Android version and phone type, I had the same problems. The above procedure works for all versions.

I don't think it makes a difference to have the cable connected or not when calling Initialize. The program only initialize internal variables depending on if it's for Serial OTG, BT or WIFI connection. The program does not look for any device or connection before Open.
But you may have to disconnect and reconnect the cable, to make Android to detect the OTG device after an error.
You may also have to restart the AI Companion.

I seem to remember that some phones start charging when the OTG cable is plugged in.

However, this does not happen if Initialize SerialOTG is called before.


Initially I used this UNO board and the serial connection doesn't work.

Them I changed it for this board and the serial connection works now.

So, my question is, if this extension don't work with chinese boards?.

Thansk a lot Mr. @rkl099 for the help

Thanks Mr., but the problem was the Arduino board.

It works with most Arduino boards, but the built in AI Serial only works with original Arduino UNO and boards with the same USB-serial converter. My advice is to test with a serial terminal APP so you can verify that your USB OTG cable works, before you start to test your AI APP.
Make a simple program in the Aurdino that in a loop read a character and write it back on the serial line.
The you can verify step for step:
first Initialize (I normally put this in screen initialize)
.Then Open. First time, do you get a pop-up that asks for permission to use USB device?
Net time you press open, do you get IsOpen=True?
If this is ok, but communication does not work, check baudrate stopbits parity etc.

It seems to be the same converter chip on the boards, 16u2 programmed as an USB.serial converter. If you can program the first board, then you shall be able to use it with SerialOTG. You can test it with a computer an see what it reports. It should be VID=0x2341 (PID=0x0043) and cdc_acm protocol to be recognized as an UNO. I use linux and dmesg to list this or use device manager in Windows.

Arduino forum also mentions VID=0x2a03 as an UNO. Can anyone verify this?
This can be included in SerialOTG.

It depends on the chip that controls the USB signal, I have several Chinese-made Arduinos with the CH340G and they work with this extension.

Hello Mr. @rkl099 , I used the extencion SerialOtg to work with Android 11; recently updated to Android 12 and the extension is broken. Get an Runtime error message indicating that the app must specify FLAG_IMMUTABLE when creating a PendingIntent. Hopefully you can update it?. It has been a very useful extension. Thanks very much.

Have you tried the updated version in GitHub - rkl099/Appinventor_Debug: Debug versions: SerialOTG, Modbus and test programs (Note: can be changed any time). ?
This version should work with Android12, but it also have some other small changes.
I don't have an Android12 device, so I have to wait for user response before I update the main directory.

1 Like

Thanks a lot!, it works with Android 12.

got the same issue, it wont open serial port, i used this solution but it didnt work..
got Android10,
using serialOTG.apk in the solution
but when i using the "serial usb terminal" application, i get a popup "do you want serial usb terminal have access to serialdevice?"... then i click yes and i can data coming to phone...

... not sure what i can do...

I need more information to be able to help you:

The same issue as ...?
Can you describe what happens when you try to open the serial port?
What serial device are you using?
USB serial converter, Arduino original or Arduino clone or somthing else?
Can you get VID and PID for the device using windows device manager or Linux dmesg?

it wont open the port... i use serialotg.aix version 2022-11-05, importing(upgrading) into serialotg.aia project, build and installing .apk
the device i use is a serial device, seeedstudios XIAO
i guess this is VID/PID

i connect otg-cable with the XIAO
i start the serialotg application
then i try pressing "open", response is "not open" and no led indication it did work on the XIAO

i tried also this, according to .pdf

It has been reported that there is a difference in the behavior of SerialOTG and Serial USB
Terminal. This is because SerialOTG has DTR, RTS =0 as default (as AI built in component),
SerialTerminal has DTR, RTS =1. This may be set as a property or in the blocks before open.

but it does not response...

This VID/PID is not included in the library, but can be added.
Serial over USB uses USB CDC (reference Seeed Studio XIAO SAMD21 by Nanase - Seeed Wiki) but i don't know if this is included in the bootloader. Other references talk about FDDI, but this needs a separate chip or USB converter, so i guess that this is for the chips UART pins.
Can you see in the serial terminal if it uses CDC protocol?

I succeeded to communicate using "serial USB terminal" application with 9600baud/8bit/None/1stop bits with CDC protocol. I can then see tx-led flashing on the XIAO and read the values in the terminal.

OK. I will update the VID/PID list in the library soon.

1 Like