So I have two ESP8266s connected via Serial (UART1 transmit from D4, UART0 receive on RX). I have an LED with 220Ohm resistor to ground on D1 on the receiving board. The grounds for both boards, and the LED, are connected to the same point. Both boards are connected / powered via USB. The sending script is here
// sender for test programs
int letter_out;
void setup() {
// initialize serials:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
Serial.flush();
for (int i = 65; i < 90; i++)
{
// send letter:
letter_out = i;
Serial1.write(letter_out);
Serial.write(letter_out);
delay(2000);
}
}
and the receiving code is here
// pins for the LEDs:
const int redPin = 5; //D1
bool redPinState;
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pin output:
pinMode(redPin, OUTPUT);
}
void loop() {
// if there's any serial available, swap LED state:
while (Serial.available() > 0) {
if (redPinState)
{
digitalWrite(redPin,LOW);
redPinState=0;
}
else
{
digitalWrite(redPin,HIGH);
redPinState=1;
};
Serial.flush();
}
}
So what I expect to happen is that each time I send a serial message ( single letter) from the sender, the LED on the receiver will change state. It does, but rather than going on then off then on, etc, sometimes it will go on, then brighter, then back to on, then off, then on , then bright... etc. The timing matches the change of state I expect from the send timings, but it doesnt just go on and off. I'm thinking its some sort of grounding / charging / capacitance problem?? Any ideas ? I'm attaching a photo of the setup although its hard to get clear. Blue, Orange and Green are ground wires. Red is the signal wire.