int stove;
void setup() {
Serial.begin(9600);
}
void loop(){
if (Serial3.available()>0){
stove = Serial3.read();
}
Serial.print(stove);
}
when I read my serial monitor data from the nano the value is 70.Then when i print or try to use the "stove" value in my mega sketch it ends up being 110, 113 then as my temp value increases the stove value drops. Im obviously missing something int the communication between the two boards
When your nano prints to Serial, it is converting the intenger 70 into two ascii bytes: '7' and '0' and then sending them to the Mega. The mega needs to read these values and then convert them back to an integer. Read this thread for a great overview of how to do good, reliable communication.
Also, you never initialize Serial3 inside the mega before you use it.
I tried using the "Receiving a single number from the Serial Monitor" example to my mega along with changing the Serial.available and the Serial.read to Serial3 and I am still having issue with seeing my nano output. I do not understand the string/bytes thing at all and cannot seem to pick it up for the life of me. But definitely feeling pretty stupid about not being able to get two similar boards to communicate
Write a short program for your nano that prints the number 123 every second - Serial.println(123); It would also be a good idea to blink the LED every second so you can see it is working when powered separately.
Make sure you can see that on the Serial Monitor. Then disconnect the nano from the PC and power it separately.
Now upload the second example in Serial Input Basics to your Mega, but change it so that it is receiving data on Serial3. Leave the sending unchanged.
Now connect the nano rx to the Mega tx3 and tx to rx3 and GND to GND.
When you run the program on the Mega you should see the 123 being received from the nano.
IF THAT DOES NOT WORK then stick with it until you get things sorted out, don't go trying a bunch of other things. Post the two programs that you have uploaded.
I observe that you are missing the following: 1. You have not connected MEGA and NANO. Now, connect them as follows:
DPin-2 of NANO (SRX: soft receive pin) <------------- TX3 of MEGA
DPin-3 of NANO (STX: soft transmit pin) -------------> RX3 of MEGA
GND of NANO <-----------------------------------------> GND of MEGA
2. Upload the following sketch in NANO (yours one with slight modification):
GolamMostafa:
Is there any preference in saying Serial.println(123); to saying Serial.println("123");?
I chose 123 without quotes because I believe the OP will be sending numbers rather than text. I wanted him/her to be aware of how numbers are received.
Robin2:
I chose 123 without quotes because I believe the OP will be sending numbers rather than text. I wanted him/her to be aware of how numbers are received.
Then, is it necessary to include explicitly the base of the number (which is here: DEC) in the argument of the print() method?