N
N
Nickilanto2018-11-30 12:19:17
Arduino
Nickilanto, 2018-11-30 12:19:17

Why is data not being transferred via Serial?

There are two arduino boards (actually not arduino, but TTGO Esp-32, but it doesn’t matter). The boards are connected rx-tx tx-rx respectively. The GND pins are also connected. The essence of the firmware is that "L" and "H" are sent from one board after a short period of time, which in turn turns off and on the LED on the second one (Must turn it off and on). I uploaded the firmware to both boards. I click on the Serial port view button in the Arduino ide on the first board and everything seems to be sent normally, but the LED does not blink. I press the same button on the second one and the data transfer from the first one stops abruptly. Accordingly, nothing comes to the second board. But the highlight of the program is that if you enter "H" and "L" manually in the top line in viewing the serial port, the LED lights up and goes out (moreover, it is interesting to enter "H" and "L" both in the monitor of the first and in the monitor of the second board. The result is the same). I can't understand why the data is not being transferred.
Here's the sketch itself:
Transfer board
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.print('H');
delay(500);
Serial print('L');
delay(500);
}
Receive board
const int ledPin = 2; // 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(115200);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// 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);
Serial.write('H');
}
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vanyamba-electronics, 2018-11-30
@vanyamba-electronics

Admission fee:

void loop() 
{
   // read the oldest byte in the serial buffer:
   while (Serial.available() == 0) {
      digitaWrite(blinkPin, HIGH);
      delay(100);
      digitalWrite(blinkPin, LOW);
      delay(200);
   }
   unsigned char incomingByte = Serial.read();
   // if it's a capital H (ASCII 72), turn on the LED:
   if (incomingByte == 'H') { 
      digitalWrite(ledPin, HIGH);
      Serial.print('H');
    }
    else if (incomingByte == 'L') {
        digitalWrite(ledPin, LOW);
        Serial.print('L');
    }
    else {
        Serial.print(incomingByte);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question