arduino micro to uno serial communication (SOLVED)

Hey forum,

Whatever I tried, I cannot get this setup to work.

I would like to make home automation light switch. In the wall socket, there is a push button hooked up to a arduino micro. When pressed, the micro should put a serial message on the 'bus', which is read by an arduino uno, which in his turn triggers a relay.

To simplify the setup, I have written the micro code just to send H and L to the uno, where the latter just turns his onboard led on and off. Should be so straight forward :frowning:

The arduino micro code

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print('H');
  delay(1000);
  Serial.print('L');
  delay(1000);
}

The arduino uno code

void setup () {
    pinMode(13, OUTPUT);
    Serial.begin(9600);  
}

void loop () {  
  
  if (Serial.available()) {
    /* read the most recent byte */
    int byteRead = Serial.read();
    if(byteRead == 'H'){
        digitalWrite(13, HIGH);
    }
    if(byteRead == 'L'){
        digitalWrite(13, LOW);
    }
  }

}

Of course, I have tried:

  • using serial1 procedures
  • used both serial and serial1
  • hooking usb first and last
  • making sure they have common ground
  • used serial print to debug
  • hooked serial wires first and last
  • reset when hooked
  • shout very loud: aaaaah
  • banged my head on the table

I am sure there is something I am overlooking or missing, but again, I cannot figure out what.

Maybe you can help, please

Answer given by Pert post #2

all the code for the micro should be replaced by serial1

The arduino micro code

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial1.print('H');
  delay(1000);
  Serial1.print('L');
  delay(1000);
}

Not something I have done but a similar set up HERE.
And HERE.

Note they subtle differences.

You need to change all the Serial to Serial1 in the code for your Arduino Micro board. Continue to use Serial on the code for the Uno.

Wiring should be RX-TX, TX-RX. That said, I will warn your that I have a clone Pro Micro which has the pins 0 and 1 switched (the pin labeled "TX0" is actually Arduino pin 1 and the pin labeled "RX1" is actually Arduino pin 0) you could test for this with the blink sketch and an LED or voltmeter connected to the pin.

hewi:

        digitalWrite(13, Low);

should be:

       digitalWrite(13, LOW);
1 Like