• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP32, Shift Registers, 7 Segment display, and pins – observations

Q&A Forum › Category: ESP32 › ESP32, Shift Registers, 7 Segment display, and pins – observations
0 Vote Up Vote Down
Donald asked 5 years ago

This might be off-off-topic, and not really a question, as I don’t know if Sara & Rui have any tutorials on them. I’ve spent my hobbying time the last two days trying to wrap my head around shift registers and segment LED displays. I’ve got a little digital clock project in mind that I want to incorporate with the ESP32’s wifi capabilities. I’m interested in using the 4 digit 7 segment LED display.

ESP32 Pin Choice: I’ve learned that not any three pins on the ESP32 board (I’m using a 30-GPIO board, Node32S) will work for Latch, Clock, and Data. I initially tried GPIO35,34,and 32. Nope. I searched around and found that GPIO21, 22, and 23 will work; for some reason, pins 4, 12, and 14 also work.

digitalWrite method: The Elegoo starter kit example for Shift Register and 7 segment display uses the shiftOut method, which is successful lighting up the display as expected.

shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]);

works, whereas

digitalWrite(pin,LOW or HIGH)

does not.

In case anyone else has fiddled around with SR, ESP32 and 7 segment displays…these are just my findings.

Question Tags: shift register
3 Answers
1 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi Donald.

Your first selection of pins probably didn’t work because GPIOs 35 and 34 are input only pins. You can learn more about the ESP32 pins here: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

When you say the digitalWrite method doesn’t work, what do you mean? To use that method I think you need to wire each pin of the 7-segment display to one GPIO. How are you connecting your display?

Regards,
Sara

0 Vote Up Vote Down
Donald answered 5 years ago

Hi Sara, 
I think this is one of the examples I was using that didn’t include the shiftOut method.

int DS1_pin = 4;
int STCP1_pin =3;
int SHCP1_pin = 2 ;

int digits [10][8]{
  {0,1,1,1,1,1,1,0}, // digit 0
  {0,0,1,1,0,0,0,0}, // digit 1
  {0,1,1,0,1,1,0,1}, // digit 2
  {0,1,1,1,1,0,0,1}, // digit 3
  {0,0,1,1,0,0,1,1}, // digit 4
  {0,1,0,1,1,0,1,1}, // digit 5
  {0,1,0,1,1,1,1,1}, // digit 6
  {0,1,1,1,0,0,0,0}, // digit 7
  {0,1,1,1,1,1,1,1}, // digit 8
  {0,1,1,1,1,0,1,1}  // digit 9
};


void display_digit(int d){
  if (digits[d][0]==1) digitalWrite(7, LOW); else digitalWrite(7, HIGH); //A
  if (digits[d][1]==1) digitalWrite(8, LOW); else digitalWrite(8, HIGH); //B
  if (digits[d][2]==1) digitalWrite(9, LOW); else digitalWrite(9, HIGH); //C
  if (digits[d][3]==1) digitalWrite(2, LOW); else digitalWrite(2, HIGH); //D
  if (digits[d][4]==1) digitalWrite(3, LOW); else digitalWrite(3, HIGH); //E
  if (digits[d][5]==1) digitalWrite(5, LOW); else digitalWrite(5, HIGH); //F
  if (digits[d][6]==1) digitalWrite(4, LOW); else digitalWrite(4, HIGH); //G
}

void DisplayDigit(int Digit)
{
    digitalWrite(STCP1_pin,LOW);
    for (int i = 7; i>=0; i--)
   {
    digitalWrite(SHCP1_pin,LOW);
    if (digits[Digit][i]==1) digitalWrite(DS1_pin, LOW); 
    if (digits[Digit][i]==0) digitalWrite(DS1_pin, HIGH);
    digitalWrite(SHCP1_pin,HIGH);
   }
   digitalWrite(STCP1_pin, HIGH); 
}


void setup() {  
  pinMode(DS1_pin, OUTPUT);
  pinMode(STCP1_pin, OUTPUT);
  pinMode(SHCP1_pin, OUTPUT);
}

void loop() {
for (int i=0;i<10;i++){  
  DisplayDigit(i);  
  delay(300);
}
} 

Also, it depends on if your 7 segment display is common cathode or anode…
I *think* I attempted this method using different GPIO pins than 34 and 35. 

1 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi.

That example will work if you connect each individual pin of the 7-segment display to a single GPIO. Each GPIO controls a segment of the display. That is probably an example based on the Arduino. The A segment is connected to pin 7, the B segment to pin 8 and so on.

void display_digit(int d){
if (digits[d][0]==1) digitalWrite(7, LOW); else digitalWrite(7, HIGH); //A
if (digits[d][1]==1) digitalWrite(8, LOW); else digitalWrite(8, HIGH); //B
if (digits[d][2]==1) digitalWrite(9, LOW); else digitalWrite(9, HIGH); //C
if (digits[d][3]==1) digitalWrite(2, LOW); else digitalWrite(2, HIGH); //D
if (digits[d][4]==1) digitalWrite(3, LOW); else digitalWrite(3, HIGH); //E
if (digits[d][5]==1) digitalWrite(5, LOW); else digitalWrite(5, HIGH); //F
if (digits[d][6]==1) digitalWrite(4, LOW); else digitalWrite(4, HIGH); //G
}

If you want to control it with the ESP32 that way, you need 7 GPIOs, one for each pin of the 7-segment display.

I think you’ll understand how it works if you take a look at this example with Arduino: create.arduino.cc/projecthub/SAnwandter1/programming-4-digit-7-segment-led-display-2d33f8

Let me know if this is clear.

Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.