Hey Guys!
I am working on a project with a prototype board that runs like an arduino leonardo. As such, it has both serial and serial1. I have a LoRa RN2903 chip on this board and I'm trying to set it up for communication.
Here's my issue, according to the Datasheet when I send "sys get ver" to the RN2903 which I am doing using
Serial1.write("sys get ver");
I should be receiving back version information in the form:
RN2903 X.Y.Z MMM DD YYYY HH:MM:SS
where X.Y.Z is the firmware version, MMM is month, DD is day, HH:MM:SS is hour, minutes, seconds (format: [HW][FW] [Date] [Time]). [Date] and [Time] refer to the release of the firmware.
Anyway... when I run my program...
//Global Variable Definitions
auto startup_called = false;
//Function Definitions
/*
* Startup() handles configuring the RN2903.
* ReadIncoming() returns incoming message.
* setup() configures buad rate.
* loop() calls aforementioned functions.
*/
void Startup(){
delay(1000); //I have no idea why, but it won't call Startup() unless I have this delay here.
Serial.println("** Startup Commands Sent **");
Serial1.write("sys get ver");
Serial1.write('\r');
Serial1.write('\n');
Serial1.write("mac pause");
Serial1.write('\r');
Serial1.write('\n');
Serial1.write("radio set wdt 0");
Serial1.write('\r');
Serial1.write('\n');
Serial.println("RN2903 Ready for Communication, enter text to transmit:");
}
void ReadIncoming(){
auto incomingByte = Serial1.read();
Serial.println("I received: ");
Serial.println(incomingByte, DEC);
}
void setup(){
Serial1.begin(57600);
}
void loop(){
//This IF statement processes the startup commands only one so that they don't reocur after initialization.
if (!startup_called) {
Startup();
startup_called = true;
}
if (Serial1.available() > 0) {
ReadIncoming();
}
}
I get a series of DEC or HEX bytes depending on which I call, so I am wondering two things...
1: How do I get the response the datasheet says I should get?
2: Am I already getting it in HEX/DEC and I just need to convert it?
Thanks,
David
I think this
Serial1.write("sys get ver");
should be
Serial1.print("sys get ver");
...R
Why do you say that? Don't I want to write to the serial1 port? Also, do I need a carriage return or newline character to terminate those commands?
Thanks,
David
Davidjb7:
Why do you say that? Don't I want to write to the serial1 port? Also, do I need a carriage return or newline character to terminate those commands?
You need to study the difference between Serial.print() and Serial.write(). Both send data to the serial port but Serial.write() is for sending a single byte whereas Serial.print() is for sending a string of characters.
I did not see any mention of carriage return or linefeed in the RN2903 documentation. If you do need it use Serial.println()
...R
Hey Robin, I wanted to say thanks again for your help yesterday.
If you don't mind, I have another question concerning data coming from the Serial. Is there a way to take data from Serial.Read and append all of the separate iterated bytes into a string?
//Global Variable Definitions
auto startup_called = false;
//Function Definitions
/*
* Startup() handles configuring the RN2903.
* ReadIncoming() returns incoming message and converts it for DEC to ASCII
* setup() configures buad rate.
* loop() calls aforementioned functions.
*/
void Startup(){
delay(1000); //I have no idea why, but it won't call Startup() unless I have this delay here.
Serial.println("** Startup Commands Sent **");
Serial1.println("sys get ver");
Serial1.println("mac pause");
Serial1.println("radio set wdt 0");
Serial.println("RN2903 Ready for Communication, enter text to transmit:");
}
void ReadIncoming(){
auto IncomingByte = Serial1.read();
Serial.println("RN2903 Response: ");
Serial.println(IncomingByte);
}
void setup(){
Serial1.begin(57600);
}
void loop(){
//This IF statement processes the startup commands only one so that they don't reocur after initialization.
if (!startup_called) {
Startup();
startup_called = true;
}
if (Serial1.available() > 0) {
ReadIncoming();
}
}
When the code compiles and runs I am receiving the following on the serial monitor.

If I take each of those "I Received" values and convert them from DEC to ASCII I get
"RN2903 1.0.3 Aug 8 2017 15:11:09
4294967245
ok
Which is exactly the response I want! Buttttt....... I would like to convert that answer over inside of the program and I'm not sure how to implement it, any ideas?
For the future please don't post pictures of text. Just copy and paste the text as it is almost impossible to read the picture and I can't copy and paste from it.
To answer your question I think the best starting point is to suggest that you look at the examples in Serial Input Basics - simple reliable ways to receive data.
I suspect the 2nd example will do what you want.
...R