Hi there - been using a wemos m0 clone, and have troubles using the serialusb.read, when sending 1 over the serial monitor it returns 49 followed by 10....why, works fine with nano or uno...
that's correct
49 is the ascii code for the symbol '1'
10 is a line feed
➜ post your code and explain how you configured the serial monitor
Thanks for the reply.
int incomingByte = 0 ; // for incoming serial data
#include <SPI.h>
#define Serial SerialUSB
void setup() {
while (!SerialUSB);
SerialUSB.begin(9600); // opens serial port, sets data rate to 9600 bps
SerialUSB.print ("Starting");
SerialUSB.print (x);
inputString.reserve(200);
}
void loop() {
// send data only when you receive data:
if (SerialUSB.available() > 0) {
// read the incoming byte:
x = SerialUSB.read();
// say what you got:
SerialUSB.print("I received: ");
SerialUSB.println(x);
}
}`
that cannot be the code, it would not compile as neither x nor inputString are defined.
Check again, it will be the same on Wemos as on Uno/nano. If not, you must be using 2 slightly different codes.
Also explain what, in your mind, "works fine" actually means, because we don't know that.
Thanks for the reply, works fine with uno\nano, enter 1, get "I received 1 " back on the serial monitior.
Sorry missed int x, on the code.
post the real code. you likely have a type mismatch which makes the Serial print the ASCII value instead of the char
Post your corrected code, and the output from serial monitor when you run the code on Uno/Nano, then the output you see with Wemos M0. If you do this accurately, I will use the code to test using my Nano and another SAMD21 board I have, to see if I can repeat your results.
Thanks for the help. Note that <no line entered> is selected on serial monitior
int x = 0;
int incomingByte = 0 ; // for incoming serial data
#include <SPI.h>
#define Serial SerialUSB
String inputString = ""; // a String to hold incoming data
bool stringComplete = false;
void setup() {
while (!SerialUSB);
SerialUSB.begin(9600); // opens serial port, sets data rate to 9600 bps
SerialUSB.print ("Starting");
inputString.reserve(200);
}
void loop() {
// send data only when you receive data:
if (SerialUSB.available() > 0) {
// read the incoming byte:
x = SerialUSB.read();
// say what you got:
SerialUSB.print("I received: ");
SerialUSB.println(x);
}
}
Wemos reply on the serial monitor
1 entered serial monitir "I received 49",
2 entered serial monitor "I received 50",
3 entered serial monitor "I received 51",
4 entered serial monitor "I received 52",
try serial monitor "I received 116"; "I received 114""I received 121"
nano output, had to take SerialUSB for the nano,
and the the same results !??!! - differnet from the laptop i was using last night !!....``
make that a char
char x = 0;
I'm pretty sure you'll also get numbers on a UNO because you are trying to print a number, not a character
the print function is smart - it adapts to the type of parameters you pass. if it's a number it will print the number, if it's a character it prints the character, if it's a pointer to a character - it will assume it's a null terminated char array and will print a string (c-string).
Thanks for that it helped.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.