How do I read text from USB serial (arduino)?

I would like the application in the "text 2" field to display everything that is sent via the USB port from aduino. Honestly speaking, I don't know English very well to understand video tutorials so I did it my way. And even earlier, the application turned on without problems (although it did not work), now it can not even compile and I have an error in the emulator:
"java.lang.NoClassDefFoundError: android.hardware.usb.UsbManager app inventor"

I know that the the blocks are nonsensical - I'm learning.

Hello user. Please temporarily change your editor language to English before sending your screenshot.
You might also want to disable the empty event blocks.


Done, but i'm sure i do it wrong..

I think that the following links explains your problem:

https://community.appinventor.mit.edu/t/using-serial-with-ftdi/
https://community.appinventor.mit.edu/t/otg-problem-with-clone-nano-arduino/

You can also search for ”serial” in the forum.
The suggested replacement for the built in serial component can be found at:

Good luck with your project!

ok ... but the question is, does this code that I pasted make any sense? i am learning and i am new to this. I need help to make a code to read all from serial. thx for all. I think it's not very good since the emulator doesn't even want to work.

The emulator does not work with USB OTG. You need to use AI Companion or to make an app and transfer it to your device. Your device must have OTG function and you need an USB-OTG cable to connect to arduino. (There are some emulators that work with USB, but I can't help you with that)
Your code initialize and open the serial when the screen is opened, but your Read will only read once, ehat it sent between open and read, and this will probably always be none character. The simplest way to start learning is to make a button that makes a read on "button.Click" event and display what is sent from the arduino. If you are using my extension, have a look at the time example on how to handle text messages.

I have an OTG cable, and this function is in the phone. Using the "serial monitor" program from the play store, it easily reads data from arduino. the problem is that it can not complete the compilation and when you try to run above, the error that I showed pops up. So ... that's why I am asking for the code because it is not possible to compile (compilation is not finished and I can not even check the application) so that it will "update" the USB on the phone, if it doesn't help me?

Do you have any warnings or errors in the blocks editor?
How do you try to run the code?

it doesn't work, I started writing the code and at this point I can't compile it anymore - during compilation I have the message "unable to finish .." and when I try to run the emulator it shows the error I pasted above. I wrote at the beginning that I can't run now, that I don't know myself and whether this code can work at all.

You can't use the emulator for USB!

Do you have any warnings or errors in the blocks editor?

no i meant companion ai emulator, not usb emulator. I don't have any errors during compilation, just at the end it says "unable to finish .." and ai companion pops up with this error after starting the app, which I wrote above. ps. I work on ubuntu.

I don't think companion is an emulator, just a way to transfer the application to your device.
Does this help you? Serial connection error: java.lang.NoClassDefFoundError: android.hardware.usb.UsbManager

1 Like

I have installed SerialOTG and I can see information from arduino. My application has compiled today (I couldn't and I didn't change anything yesterday) starts, but it displays only in the "serial ok" window (when serial is initialized)

OK, now se my reply above (post nr 7) about your use of read() in screen.initialize

I suggest that you call open from a button.click. You may have to respond to the first open to allow your app to use your USB-serial adapter. The second press on open will do the actual open.
Then use another button to read serial and display it. Later on, use a timer to repeatedly call read and collect characters to display your text from the aurduino

1 Like