Question about USB SERIAL read

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.

In that case, how to reset the arduino via the usb port? xD

A reset would not help? You could try something like:

Serial.begin(115200);
Serial.write(""); (Edited)
Serial.flush();

Serial.flush
"Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)"

I don't understand what it would do for me. I would like to find out from the person who created the app inventor if he can or can reset the entire arduino or whether it is possible to remove this MCU Atmega328P reset

It has nothing to do with App Inventor really, but there must be a trick that we can use, hence my suggestion.

Serial.begin(115200);
Serial.write("");
Serial.flush();

I did it, I don't know if it's right, but it's still the same. When connecting (clicking connect) I immediately get "Welcome �����"

#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.write("");
    Serial.flush();
    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) );  
    }
}

 
  

  

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.