Question about USB SERIAL read

Right - where is the input for 'username' coming from? Your phone via the App?

username = Serial.readStringUntil('\n');

Was the input of the username five characters? What is the actual username that was typed-in? I think nothing was typed, but the read is executed and doesn't stop until '\n' - so memory is read, unrecognised characters, hence the ��

Edit: In other words, the code is reading User Input before the User has typed-in a name.

Concerning your App Inventor project, the Clock Timer is setup to constantly read from the moment the App is opened. It is also reading every 1 millisecond? You have one serial channel for read and write? That means you need an event for read and an event for send to ensure the two streams do not coincide.

From the documentation of the extension, file SerialOTG_1.4.pdf:

“Some adapters requires RTS=1 (and/or DTR=1) to communicate. This is true for Arduino Pro Micro, 32U4 chip implementing CdcAcm.

Dtr is used to reset Arduino.”

Normally you can reset an Arduino if you toggle the DTR signal. I don’t know the exact timing for an Arduino Mega.

Isn't that going to flush the existing Sketch?

No, it resets to the bootloader that waits for a new sketch. After a timeout it restarts the previous loaded sketch. (the same thing happens if you press the reset button, or starts the Arduino serial monitor)

Try the attached App Inventor Project. It isn't necessarily going to fix the sending of text to the terminal on first connection but it should prevent the App freezing from trying to send and receive at the same time.

A1_Test1.aia (193.5 KB)

OK - can we use:

SetDTR

to reset?

"Server error: could not upload project. Please try again later!"

I already have 20 minutes, I guess

edit:

i cant upload to the server, error all the time

I just uploaded to App Inventor without issue.

Make sure App Inventor is the 'King' of the Browser - no other Websites (or other computers) are eating your Broadband.

Only use FireFox -there is a glitch in the latest Chrome v100.0.4896.127 which could cause an issue with your computer locking up @ 100% memory used.

What do you know, Google have updated Chrome to v101.0.4951.54, hopefully fixes their issue.

Still the same, it seems to me that opening the show or initializing is still sending something. Or the arduino doesn't reset completely. When "clicking connect", it asks for permissions each time the program is restarted.


'Allow the application to access the device null'

So modifying the program, how will I learn XD Because I would have to understand how EXACTLY the serial works. Then I would know what to modify. I was thinking about isAlphaNumerical () yet, but I can't program yet XD

The App (Serial OTG extension) isn't sending anything as far as I can tell, but the Sketch seems to run the loop prematurely. That's either a fault of the Sketch code or the chip bug mentioned before.

As Rolf Kardell (rkl099, extension developer) has said, Dtr can be used to reset the Arduino without flushing the existing Sketch. I don't know how to do this via the App, but the extension does have a Dtr function.

Try this Project (note, untested here as I do not have the hardware):
A1_Test2.aia (194.4 KB)

I'll check back soon, thanks so much for your help.

Your program doesn't work, but it doesnt matter., I guess this DTR solves everything.

I installed the SerialOTG application and tried connections with and without DTR. So the DTR resets the board and when it connects, it normally asks for the nickname, but I need to find out if the DTR affects the operation yet, or should it be turned off while downloading and uploading data from and to the arduino. I do not know what the DTR really is, but I will read it in a moment. Sorry for english.

I think the Arduino needs to be hard wired in order to allow an App to reset DTR.

I still think there may be a way to re-write the Sketch to prevent the issue, which is why I asked for a link to it on the Arduino forum.

I do not understand what you mean. I look at the arduino and with the option enabled, the led "power" icon on the arduino goes off (that is, it resets during serial connection) when the DTR option is off the led does not go out. which sketch do you need?

I want to see the forum posts from where you downloaded the Sketch.

This is interesting about DTR reset:

Try this?
A1_Test3.aia (194.5 KB)