arduinonodemcushift-register

Unable to update shift register with NodeMCU


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.


Solution

  • 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