i have a wemos d1 mini as the master sending the H and L and i have a arduino leonardo receiving the command and toggling an LED pin (i have changed my LED pin to 2).
If i connect each one to the serial monitor in arduino IDE and open the monitor. I can see that the wemos is sending H and L correctly. And if i type in manually H or L in serial monitor while connected to the leonardo, it toggles the LED correctly.
But if i power the units from an external power supply, nothing happens, no serial is sent. and the serial LED on the leonardo does not flash saying its sending or receiving serial data at all.
I have connected RX to TX and TX to RX, baud rates for both are 9600, and i have a common ground.
(I also have a common 5v, not sure if this makes a difference)
using arduino 1.8.8 with the lastest board managers for both leonardo and wemos.
I cant, for the life of me figure this out. I have tried multiple boards. including another mega. and nothing happens when they are seperated from the PC, but they all do as they should when plugged into USB and using serial monitor to check/send commands.
You have not posted your pair of programs so it is impossible to suggest how to improve them.
A diagram that clearly shows all your connections would also be useful.
The Pins marked Rx and Tx on a Leonardo are Serial1
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
pert:
Do you have your Leonardo connected to the computer using the USB jack?
Yes tried with USB and without USB
Robin2:
You have not posted your pair of programs so it is impossible to suggest how to improve them.
A diagram that clearly shows all your connections would also be useful.
The Pins marked Rx and Tx on a Leonardo are Serial1
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker
...R
My code is the exact examples in the link i provided, i did not change anything.
That could be partly the cause. The code im using on the Leonardo is Serial.begin, not Serial1.begin.
So i cannot just send a single character like H or L and have it read on the other arduino? I need to have it send with the start marker, then value, then comma and another value (if needed), then end marker?
I can put this on the leonardo. but change Serial to Serial1? Right?
and then this code
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
on the Mega, and change Serial to Serial 1, and then plug my RX and TX wires into RX1 and TX1? Obviously the baud matches. and make sure RX>TX and TX>RX right?
It should then work?
One question, If i use RX0 and TX0 on the Mega, will i be able to plug the USB in and read from the serial monitor at the same time as it receives the commands? Or can you only use the USB OR RX0 and TX0 one at a time, do they conflict with each other.
chemmings:
on the Mega, and change Serial to Serial 1, and then plug my RX and TX wires into RX1 and TX1? Obviously the baud matches. and make sure RX>TX and TX>RX right?
That's correct.
For anyone else looking at the tutorial, I skimmed over it and got confused because I assumed chemmings was using the "Sender Code" (on the WeMos D1 Mini) and "Receiver Code" (on the Leonardo) code at the bottom of the page. I now realize that chemmings was using the "Simple Code" on the WeMos D1 Mini and the "Physical Pixel" code on the Leonardo.
chemmings:
One question, If i use RX0 and TX0 on the Mega, will i be able to plug the USB in and read from the serial monitor at the same time as it receives the commands? Or can you only use the USB OR RX0 and TX0 one at a time, do they conflict with each other.
Try it and see?
RX0/TX0 are on the HardwareSerial instance Serial of the Mega.
The baud rate of your serial monitor will need to match the program.
You can perhaps monitor the line, but trying to write onto it from the console would create a conflict.
Well it works. The only thing that didn't work was because I wasn't using serial1 on the Leonardo. I had a nano that I was trying with for hours but it seems that one had other issues. As soon as I used the Leonardo and used serial1 instead of serial it worked great. Thanks all