1

I'm trying to connect two D1 Mini's together as a POC. There is a switch on one and a 7 segment display on the other

I have the pins setup from TX>RX and RX>TX

First ESP8266:

int SWITCH_PIN = D5;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(SWITCH_PIN, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  if(digitalRead(SWITCH_PIN) == HIGH)
  {
    Serial.println(1);
    digitalWrite(LED_BUILTIN, HIGH);
  }
  else
  {
    Serial.println(0);
    digitalWrite(LED_BUILTIN, LOW); 
  }
}

Second ESP8266:

#include "DigitLedDisplay.h"
DigitLedDisplay ld = DigitLedDisplay(D6, D5, D0);

void setup() {

  Serial.begin(115200);
  
  ld.setBright(10);
  ld.setDigitLimit(8);
  
  for (long i = 0; i < 100; i++) {
    ld.printDigit(i);
    delay(25);
  }
  
}

void loop() {
  delay(1000);
  if(Serial.read() == 1)
  {
    ld.printDigit(11111111);
  }
  else if (Serial.read() == 0)
  {
    ld.printDigit(22222222);
  }
  else
  {
    ld.printDigit(33333333);
  }
}

As far as I can tell the second ESP8266 isn't getting anything from the first. What am I doing wrong?

Thanks in advance for the help

4
  • You forgot to ask a question. Jun 18, 2021 at 9:29
  • updated with a questions now
    – Saars
    Jun 18, 2021 at 9:37
  • Serial.println(1); sends '1', not 1, so use Serial.read() == '1'
    – Juraj
    Jun 18, 2021 at 9:50
  • Sigh... Thanks for that I actually get the correct data back sometimes, but the output seems to swap between correct and the "else" status constantly
    – Saars
    Jun 18, 2021 at 10:09

1 Answer 1

1

Thanks to Juraj it was an easy fix

Missing quotes around the text and changing some code

void loop() {
  if (Serial.available() > 0)
  {
    // read the incoming byte:
    incomingByte = Serial.read();
  }
  if(incomingByte == '1')
  {
    ld.printDigit(11111111);
  }
  else if (incomingByte == '0')
  {
    ld.printDigit(22222222);
  }
}

adding "if (Serial.available() > 0)" works to make it only update when the serial buffer is full

The delay was also causing issues with where it was located so just removed that

1
  • this will ld.print every loop if incomingByte is '0' or '1'
    – Juraj
    Jun 18, 2021 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.