Question about USB SERIAL read

I have a question, I have an arduino which, when connected, sends the text "Enter name". After connecting the arduino with an OTG cable in the "Serial USB monitor" application (from the play store), I normally see "enter name". In app inventor, I set it to connect in the application after pressing the "connect" button. But when plugging in the cable, I get the message "allow the application to null?" (or something like that - it's about usb) I confirm and I see illegible two stamps that were somehow sent by phone or more by an application and the name has been set to these two strange stamps (diamond with an icon)


and here is code from arduino (simple code- maybe someone will take - chat for arduino with NRF24L01 for 2 devices via USB serial):

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   9
#define CSN_PIN 10

const byte Address[5] = {'N','e','s','s','y'};

RF24 radio(CE_PIN, CSN_PIN);

String username = "";
String dataInput;
char dataToSend[32];
char dataReceived[32];


void setup() {
    Serial.begin(115200);
    Serial.println("Enter username...");
    
    radio.begin();
    radio.setPALevel(RF24_PA_MAX);
    radio.setDataRate(RF24_1MBPS);
    radio.setRetries(3, 5);
    radio.openWritingPipe(Address);
    radio.openReadingPipe(1, Address);
}


void loop() {

  // set username
  while (username == "") {
    if ( Serial.available() ) {
      username = Serial.readStringUntil('\n');
      Serial.print("Welcome ");
      Serial.println(username);
    }
  }
  // listen for radio data
  radio.startListening();
   if ( radio.available() ) {
    // read data from radio
    radio.read( &dataReceived, sizeof(dataReceived) );
    Serial.println(dataReceived);  
}
    if( Serial.available() ) {
      // stop listening on radio
      radio.stopListening();
     
    // get serial input
    dataInput = "[" + username + "] " + Serial.readStringUntil('\n');
    Serial.println(dataInput);
    dataInput.toCharArray(dataToSend, 32);

    // send data
    radio.write( &dataToSend, sizeof(dataToSend) );  
    }
}

 
  

  

What do I have to do so that the application does not send any information to the arduino when connecting and why is it happening at all?

I downloaded the SerialOTG extension

https://github.com/rkl099/Appinventor-SerialOTG/blob/main/com.SerialOTG.aix

I have a program like this:


But every time it connects when it asks whether to allow connection to "null" (serial) it sends some data and answers itself by typing nickname. The result is 5 diamonds with question marks inside. Someone can solve it for me?

It would seem your final problem is with the SerialOTG extension, which is necessary for USB Serial on App Inventor as AI2 does not include the d2xx.jar needed.

  1. Screenshot the system message and the 'stamps'.
  2. What is the model name of your Arduino?
  3. What USB to Serial chip does your Arduino have?
  1. After connecting the arduino, the program replies itself and the nickname is as follows:
    "�����"
    but in computer serial monitor nickname is empty - no letters (when i chat with second arduino from phone)
  2. Arduino Mega 2560 model (made in Italy) as in the picture.
  3. Chip - I'm not sure how to 100% check.
    arduino-a000067
    And I do so that I create the * apk file and put it on the phone and install it.

The message read from arduino as DEC is:
87 101 108 99 111 109 101 32 240 240 240 240 13 10

87 ...- 32 thats "welcome" and "240 ..- 240" nickname "13 10" i dont know

result:

"Welcome ðððð"

That's CR LF (Carriage Return + Line Feed) as used by Windows OS to define 'go to new line'

240 = the symbol ð (or other, there isn't a formal ASCII code for 240)

Arduino Mega 2560 is only compatible with USB 2 ports and cable.

You may be able to verify the USB chip (16U2?) - it's probably going to be close to the USB port. I have read that the chip is the same as the UNO's, which is directly supported by the latest version of the SerialOTG extension:

So to recap, you are seeing the ASCII code on the Arduino Terminal, but not on your phone? I see your Smart Phone is Android 9 - but what make and model? Samsung and Huawei can be a pain because they customise the OS (Android is Open Source).

If the devices both send and receive, there can be issues - when using Serial with Bluetooth, two Serial channels can be used to simplify. From your code, you are entering the Username via the Arduino Terminal? Where did the Sketch come from? The radio functions imply wireless comms......

1 Like

So i have chip MEGA 16U2 1546 PH A3M2MA.
I have a Xiaomi redmi note 9 pro phone. What do you mean with "USB 2"? USB 2.0? I have USB C and OTG adapter. So it's like this:

I connect one arduino to the computer, it shows "enter nickname", I enter nickname and arduino replies "Hello nick1" and with each message sent I have the nickname "nick1". When I connect the cable to the arduino, every time I click "connect" in the application, she asks me if I can "allow this device to null" (something like that - but it's about usb), it gives "yes". And instead of the information "enter name" I have "hello �����" nickname is already entered, it seems to me that during initialization these characters are sent but I don't know. The sketch of arduino comes from .. arduino forum (it works without any problems on a computer or android programs, eg "Serial USB Monitor" (from the play store)

I read on the Arduino website that USB 2 is required - that may only mean USB 1 is insufficient but doesn't your board have a USB 2 port, not USB C?

I think that the USB standard is at least 2.0 required. But it works because it shows well in other applications, I wanted to do my own, but it adds "input" some data to the USB.

We can't feed on vague - we need to know the exact messages as these are a potential clue s that can lead to identifying the cause of the issue.

Do you have a schematic of your whole Hardware setup? Your description is difficult to understand - it has the tone of we know what you are doing - but we don't! We don't know the details, I'm having to ask too many questions :upside_down_face:

What is your goal - what do you hope to achieve that the "Serial USB Monitor" App does not already deliver?

What is your goal - what do you hope to achieve that the "Serial USB Monitor" App does not already deliver?

I am on the programming forum and I would like to make my application and you recommend that I use the program from the play store. xD

It is simple by me on logic, but I'm not a programmer to handle it. I know that when trying to connect, the phone sends some characters to the terminal and I don't want it. That's all I mean.

We need to see your hardware setup and your App Inventor Project file (.aia). Not convinced about the Sketch - post the link to it.

[quote="OMGlinuxIS, post:11, topic:57116"]
you recommend that I use the program from the play store
[/quote] I didn't make a recommendation but I did ask a question. :koala:

A1.aia (191.7 KB)

I haven't used the Arduino Mega, so I can't test.

In your code we see that you are using Arduino and a module with NRF24L01. I made a similar assembly but with Arduino UNO and Bluetooth.
https://community.appinventor.mit.edu/t/radio-frequency-modules-arduino-bluetooth-hc-06-fm/24346/10

How are your devices connected?

2 Likes

But that's not a problem, just app sending some data on connection. I know that you can modify the program on arduino, but I prefer the line to be "clean" from the beginning because it can be very useful.

9 ce
10 csn
vcc 5v
mosi 11
miso 12
sck 13
gnd gnd

How is your mobile connected to the Arduino?
(I guess otg cable + usb cable)

How you have connected your Arduino to the PC to see the information of the Serial Monitor. I assume you only have the receiver connected to the PC.

I have 2x Arduino 2xNRF24l01 (one arduino is arduino mega but it does not matter, the connection of the pins is only different) the programs on both arduino are THE SAME. According to your tutorial, I can send data via arduino with nrf and then bluetooth or vice versa using additional TX and RX ports on the arduino MEGA.

Have you tried my code (changing pin number pin in NRF) using OTG instead of Bluetooth?

It will definitely be the second function, but first I would like to deal with the cable connection. I would like to remove these characters when connecting,
Here's something, but I don't know in the end .. my English is too weak and the translator doesn't always translate well. Re: Data Input demo sketch - #12 by Robin2 - Programming Questions - Arduino Forum

Re your link to Arduino Forum:

The ATmega16U2 has a bug in firmware. When you open the COM port without resetting the MCU Atmega328P the ATmega16U2 send a pulse to the Atmega328P RX line (and also to the USB lines but it’s ignored, I think) that is interpreted as data depending on baud rate. If you use 9600 is ignored but starting from about 38400 it appears as character.

I doesn’t appear if you use another chip as serial/USB converter, for example clones that use CH340.