Unable to update shift register with NodeMCU

171 views Asked by At

I am working on a project where I need 9 7-segment displays. I use 9 shift registers for this.

I tested the shift registers with an Arduino Nano and everything worked. I then copied/edited the code over for use in a NodeMCU (ESP8266 wifi board) and for some reason the function to write to shift registers seems to be broken.

This is the code now:

void writeBytes(uint8_t bytesToWrite[]){
  Serial.println("test!!!");
  //Run through the 9 bytes in bytes to write.
  for(int q = 0; q < 9; q++) {
    //Loop through the 8 bits.
    for(int i =0; i < 8; i++) {
      //Check if the msb = 1
      if(0x80 & bytesToWrite[q]) {
        digitalWrite(dataPin, HIGH);
        delay(delayTime);
        digitalWrite(clockPin, HIGH);
        delay(delayTime);
        digitalWrite(clockPin, LOW);
        delay(delayTime);
        digitalWrite(dataPin, LOW);
        delay(delayTime);
      } else {
        digitalWrite(clockPin, HIGH);
        delay(delayTime);
        digitalWrite(clockPin, LOW);
        delay(delayTime);
      }
      //Shift all the bits one up.
      bytesToWrite[q] = bytesToWrite[q] << 1;
    }
  }
  //Turn on the out pin, so it will output.
  digitalWrite(outPin, HIGH);
  delay(delayTime);;
  digitalWrite(outPin, LOW);
  delay(delayTime);
}

I have checked if I used the right pins and checked if if those pins actually turned on. I also checked if the function would get executed and would be passed the right variables and it does.

This same function works on an Arduino Nano. But it won't work on a NodeMCU. The NodeMCU has a higher clock frequency. So I tried adding delays in. But it didn't work.

2

There are 2 answers

1
oedze On BEST ANSWER

The pin numbers on the NodeMCU do not match the pin numbers on the datasheet. The correct pin numbers can be found here: https://github.com/esp8266/Arduino/issues/584

2
Mathews Sunny On

The error might be because:

  1. Either there was a mistake when you copied the code.
  2. Or You haven't pasted it correctly.
  3. Some edits might also cause the same effect.
  4. It might be because of trouble with hardware, loose contacts etc.

(You should avoid use of delay if possible, because the developers say using them would give overhead, I think you should take care of it).