-->
Page 1 of 1

4 digit 7 segment display clock, help appreciated

PostPosted: Sat Dec 05, 2020 11:26 am
by oxymoron
Hey,

I'm a bit desperate, because I tried to build a NodeMCU powered WiFi-Clock using a 4 digit seven segment display. As shown in the code block my programming skills are very poor.
Flashed on the ESP8266 the code just shows 3 digits and the forth digit is dark. Not every number is displayed correctly, BUT I checked the wiring (including resistors) merely a thousand times.

I just need a helping hand, giving me advice to make this display work correctly. Would be awesome!


Code: Select all#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>


// ESP8266 Pins
int aPin = 14;  //         A
int bPin = 16;  //    ________
int cPin = 1;  //    |        |
int dPin = 13;  // F |        |  B
int ePin = 15;  //   |   G    |
int fPin = 0;  //    |________|
int gPin = 10;  //   |        |
int GND1 = 2; //     |        |
int GND2 = 4; //   E |        |   C
int GND3 = 5; //     |________|
int GND4 = 3; //       
int dPnt = 12;//         D       O dPnt

int DTime = 1; //delay für Itterationen, 16ms default, 4 ms jetzt


// Netzwerk-Credentials
const char *ssid     = "ssid";
const char *password = "password";

// NTP Client
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

void setup()
{
  pinMode(aPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(cPin, OUTPUT);
  pinMode(dPin, OUTPUT);
  pinMode(ePin, OUTPUT);
  pinMode(fPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(GND1, OUTPUT);
  pinMode(GND2, OUTPUT);
  pinMode(GND3, OUTPUT);
  pinMode(GND4, OUTPUT);
  pinMode(dPnt, OUTPUT);
 
  // Serial Monitor
  Serial.begin(115200);
 
  // Connect to Wi-Fi
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

// NTPClient initialisieren
  timeClient.begin();
  timeClient.setTimeOffset(3600);
}


void loop()
{
 
  // alle digits ausschalten
  digitalWrite( GND1, HIGH);
  digitalWrite( GND2, HIGH);
  digitalWrite( GND3, HIGH);
  digitalWrite( GND4, HIGH);

 
  timeClient.update();

  int currentHour = timeClient.getHours();
  int digi1;
  digi1 = currentHour/10;
 
  int digi2;
  digi2 = currentHour%10;
   
  int currentMinute = timeClient.getMinutes();
  int digi3;
  digi3 = currentMinute/10;
 
  int digi4;
  digi4 = currentMinute%10;
 
  digitalWrite( GND4, LOW);    //digit 4
  pickNumber(digi4);
  delay(DTime);
  digitalWrite( GND4, HIGH);
 
  digitalWrite( GND3, LOW);    //digit 3
  pickNumber(digi3);
  delay(DTime);
  digitalWrite( GND3, HIGH);
 
  digitalWrite( GND2, LOW);   //digit 2
  pickNumber(digi2);
  digitalWrite(dPnt, HIGH); //Dezimalpunkt
  delay(DTime);
  digitalWrite( GND2, HIGH);
  digitalWrite(dPnt, LOW);
 
  digitalWrite( GND1, LOW);   //digit 1
  pickNumber(digi1);
  delay(DTime);
  digitalWrite( GND1, HIGH);
}
 
void pickNumber(int x){
   switch(x){
     case 1: one(); break;
     case 2: two(); break;
     case 3: three(); break;
     case 4: four(); break;
     case 5: five(); break;
     case 6: six(); break;
     case 7: seven(); break;
     case 8: eight(); break;
     case 9: nine(); break;
     default: zero(); break;
   }
}

void clearLEDs()

  digitalWrite(  aPin, LOW); // A
  digitalWrite(  bPin, LOW); // B
  digitalWrite(  cPin, LOW); // C
  digitalWrite(  dPin, LOW); // D
  digitalWrite(  ePin, LOW); // E
  digitalWrite(  fPin, LOW); // F
  digitalWrite(  gPin, LOW); // G
  digitalWrite(  dPnt, LOW); // Dezimalpunkt
}

void one()
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void two()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, HIGH);
}

void three()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, HIGH);
}

void four()
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void five()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void six()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void seven()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void eight()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void nine()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void zero()
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, LOW);
}


Re: 4 digit 7 segment display clock, help appreciated

PostPosted: Tue Dec 08, 2020 8:17 am
by QuickFix
I hope you're either using LCD 7 segment displays or are buffering the I/O ports with transistors: the GPIO's of an ESP can only source around 12mA and a single (red) LED segment can easily draw 20mA (it may work in the beginning, but might/will fail when used for a prolonged period of time).

Then your current problem (having had a quick glance at it):
  • GPIO1 and GPIO3 are used for serial, so you can't use serial at the same time (remove the "Serial.XXX" lines)
  • GPIO10 is used by the flash memory, you can't use that one
Image

For ease of programming and hardware (saving GPIO's), you might want to consider using a shift register instead. :idea:

Re: 4 digit 7 segment display clock, help appreciated

PostPosted: Tue Dec 08, 2020 12:52 pm
by btidey
This won't help if you are fixed on a particular display but given a choice one can use a 4 digit display like a TM1637 which is controlled by I2C and needs just 2 GPIO.

Re: 4 digit 7 segment display clock, help appreciated

PostPosted: Sat Dec 12, 2020 1:26 pm
by StanJ
QuickFix wrote:I hope you're either using LCD 7 segment displays or are buffering the I/O ports with transistors: the GPIO's of an ESP can only source around 12mA and a single (red) LED segment can easily draw 20mA (it may work in the beginning, but might/will fail when used for a prolonged period of time).


Absolutely true, but the GPIOs can sink around 20mA continuously according to a post at Espressif's BBS.

Post your schematic, oxymoron.