I'm working on a project where I have a Feather ESP-12S microcontroller running Arduino IDE sending data via serial to a 4D Systems Diablo display (which has an onboard microcontroller) to show graphics, but I've been running into a strange issue.
If I have the TX/RX hooked up when the system is powered up, the serial out is shifted back by one character. As an example, if I was to do:
Serial.write(1);
Serial.write(2);
Serial.write(3);
When I serial read on the Diablo, I get -1, then 1, then 2. If I were to serial read again, I would get a -1. However, the next time I write from the Feather to the Diablo, I would read a 3. The code on the Feather is not stopping anywhere and runs fine.
Interesting to note, if I plug the RX/TX cables in after powering up both screen and microcontroller, this problem doesn't happen.
The code below is what I was using to debug this. Essentially, the Neopixel ring should be green on even numbers and red on odds. My issue is causing these to be switched.
After a startup handshake (sending the value 9 back and forth), the Diablo just takes the value of i and prints it to the display.
Any help would be greatly appreciated, I'm completely stumped.
#include <Adafruit_NeoPixel.h>
#define PIN 14
#define NUMPIXELS 24
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int i = 0;
void setup() {
Serial.begin(19200);
// Wait for serial
while (! Serial) {
delay(1);
}
delay(3000);
while (Serial.read() != 9) {
Serial.write(9);
delay(100);
}
pixels.begin();
for (int j = 0; j < NUMPIXELS; j++){
pixels.setPixelColor(j,pixels.Color(0,0,0));
}
pixels.show();
}
void loop() {
Serial.write(i);
i = i + 1;
if (i%2 == 1) {
for (int j = 0; j < NUMPIXELS; j++){
pixels.setPixelColor(j,pixels.Color(10,0,0));
}
pixels.show();
}
else if (i%2 == 0) {
for (int j = 0; j < NUMPIXELS; j++){
pixels.setPixelColor(j,pixels.Color(0,10,0));
}
pixels.show();
}
if(i>9) {
i = 0;
}
delay(3000);
}