4-Digital Display

From
Jump to: navigation, search

Grove - 4-Digital Displays (Seeed-Studio)

Caractéristiques

Grove compatible interface (3.3V/5V)

connect to D2/D3

4 digit red alpha-numeric display
8 adjustable luminance levels

Support

4-Digital Display recto.jpg 4-Digital Display verso.jpg 4-digit display interface.jpg

Drivers

chip - TM1637

Librairies

TimerOne library

Grove_4Digital_Display Library TM1637.h Seeed-Studio/Grove_4Digital_Display

Four-Digit Display Suli Library Four_Digit_Display.h Seeed-Studio/Four_Digit_Display_Suli

Voltage

3.3V ~ 5.5V

Code Exemple->DigitalTube->ClockDisplay

sur le Port D2

Pinout Grove Shield Arduino Nano.JPG Seeeduino-nano-connect.png 4-Digital Display recto.jpg


Copier les deux librairies dans C:\Program Files (x86)\Arduino\libraries, exécuter Arduino IDE, chercher l'exemple, choisir Arduino UNO, et le port COM

	//  Author:Frankie.Chu
	//  Date:9 April,2012

	#include <TimerOne.h>
	#include "TM1637.h"
	#define ON 1
	#define OFF 0

	int8_t TimeDisp[] = {0x00,0x00,0x00,0x00};
	unsigned char ClockPoint = 1;
	unsigned char Update;
	unsigned char halfsecond = 0;
	unsigned char second;
	unsigned char minute = 0;
	unsigned char hour = 12;


	#define CLK 2//pins definitions for TM1637 and can be changed to other ports    
	#define DIO 3
	TM1637 tm1637(CLK,DIO);

	void setup()
	{
	  tm1637.set();
	  tm1637.init();
	  Timer1.initialize(500000);//timing for 500ms
	  Timer1.attachInterrupt(TimingISR);//declare the interrupt serve routine:TimingISR  
	}
	void loop()
	{
	  if(Update == ON)
	  {
		TimeUpdate();
		tm1637.display(TimeDisp);
	  }
	  
	}
	void TimingISR()
	{
	  halfsecond ++;
	  Update = ON;
	  if(halfsecond == 2){
		second ++;
		if(second == 60)
		{
		  minute ++;
		  if(minute == 60)
		  {
			hour ++;
			if(hour == 24)hour = 0;
			minute = 0;
		  }
		  second = 0;
		}
		halfsecond = 0;  
	  }
	 // Serial.println(second);
	  ClockPoint = (~ClockPoint) & 0x01;
	}
	void TimeUpdate(void)
	{
	  if(ClockPoint)tm1637.point(POINT_ON);
	  else tm1637.point(POINT_OFF); 
	  TimeDisp[0] = hour / 10;
	  TimeDisp[1] = hour % 10;
	  TimeDisp[2] = minute / 10;
	  TimeDisp[3] = minute % 10;
	  Update = OFF;
	}


il affiche 12:00 et ensuite 12:01 ainsi de suite...


Code Wokwi 1 🛜

wokwi-esp32-devkit-v1, Anonymous
https://wokwi.com/projects/376726394500720641
(GMT+7 for Bangkok, Thailand)

  1. define CLK_PIN 2 // D2 sur XIAO-ESP32S3
  2. define DIO_PIN 3 // D3 sur XIAO-ESP32S3

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG 4-Digital Display recto.jpg

Grove Base for XIAO (Port D1) ✅
XIAO-ESP32S3
4-Digital Display


#include <WiFi.h>
#include <TM1637Display.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

#define CLK_PIN 2 // GPIO2
#define DIO_PIN 3 // GPIO3

// Initialize the TM1637 display
TM1637Display display(CLK_PIN, DIO_PIN);

const char * ssid="Wokwi-GUEST";
const char * password="";

// Define NTP Server
const char* ntpServerName = "pool.ntp.org";
// Initialize UDP client for NTP
WiFiUDP ntpUDP;
// Define time zone (GMT+2 for Zurich Switzerland)
const long utcOffsetInSeconds = 2 * 3600;
NTPClient timeClient(ntpUDP, ntpServerName, utcOffsetInSeconds);

void setup() {
  Serial.begin(115200);

  // Initialize the TM1637 display
  display.setBrightness(0x0a); // Set the brightness (0x00 to 0x0f)

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 
  // Initialize the time client
  timeClient.begin();
  timeClient.setTimeOffset(utcOffsetInSeconds);
}


void loop() {
  // Update the time from the NTP server
  timeClient.update();
  // Get the current time
  uint8_t hours = timeClient.getHours();
  uint8_t minutes = timeClient.getMinutes();
 
  if (hours >= 7 && hours < 18) {
    display.setBrightness(0x0f); // Set the brightness to high
  } else {
    display.setBrightness(0x07); // Set the brightness to medium
  }
  // Display the time on the TM1637 display
  display.showNumberDecEx(hours * 100 + minutes, 0b11100000, true); //Flash every 2 seconds
  
  uint8_t seconds = timeClient.getSeconds();
  Serial.println((String)hours + ":" + minutes + ":" + seconds);
  delay(1000); // Update the display every second
  
}



Code Wokwi 2 🛜

code modifié ajout du clignotement des 2 points toutes les secondes 

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG 4-Digital Display recto.jpg

Grove Base for XIAO (Port D1) ✅
XIAO-ESP32S3
4-Digital Display

#include <WiFi.h>
#include <TM1637Display.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

#define CLK_PIN 2 // GPIO2
#define DIO_PIN 3 // GPIO3

// Initialize the TM1637 display
TM1637Display display(CLK_PIN, DIO_PIN);

const char* ssid = "Wokwi-GUEST";
const char* password = "";

// Define NTP Server
const char* ntpServerName = "pool.ntp.org";
// Initialize UDP client for NTP
WiFiUDP ntpUDP;
// Define time zone (GMT+2 for Zurich Switzerland)
const long utcOffsetInSeconds = 2 * 3600;
NTPClient timeClient(ntpUDP, ntpServerName, utcOffsetInSeconds);

void setup() {
  Serial.begin(115200);

  // Initialize the TM1637 display
  display.setBrightness(0x0a); // Set the brightness (0x00 to 0x0f)

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Initialize the time client
  timeClient.begin();
  timeClient.setTimeOffset(utcOffsetInSeconds);
}

void loop() {
  // Update the time from the NTP server
  timeClient.update();

  // Get the current time
  uint8_t hours = timeClient.getHours();
  uint8_t minutes = timeClient.getMinutes();
  uint8_t seconds = timeClient.getSeconds();

  // Adjust brightness based on time of day
  if (hours >= 7 && hours < 18) {
    display.setBrightness(0x0f); // High brightness
  } else {
    display.setBrightness(0x07); // Medium brightness
  }

  // Blink the colon every second: ON if even second, OFF if odd
  uint8_t colonState = (seconds % 2 == 0) ? 0b11100000 : 0b00000000;

  // Display time with blinking colon
  display.showNumberDecEx(hours * 100 + minutes, colonState, true);

  // Print time to serial monitor
  Serial.println((String)hours + ":" + minutes + ":" + seconds);

  delay(1000); // Update every second
}



Code Wokwi 3 🛜

Code modifié ajout du DaylightSaving heure d’été / heure d’hiver

https://github.com/PaulStoffregen/Time TimeLib.h

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG 4-Digital Display recto.jpg

Grove Base for XIAO (Port D1) ✅
XIAO-ESP32S3
4-Digital Display

#include <WiFi.h>
#include <TM1637Display.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <TimeLib.h> // Nécessaire pour manipuler les dates

#define CLK_PIN 2 // GPIO2
#define DIO_PIN 3 // GPIO3

TM1637Display display(CLK_PIN, DIO_PIN);

const char * ssid = "Mon-ssid";
const char * password = "Mon-password";

const char* ntpServerName = "pool.ntp.org";
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, ntpServerName, 0); // Offset initial à 0

// Fonction pour déterminer si on est en heure d’été en Suisse
bool isDaylightSaving(int day, int month, int weekday) {
  // Dernier dimanche de mars → début heure d’été
  if (month == 3 && (day - weekday) >= 25) return true;
  if (month > 3 && month < 10) return true;
  // Dernier dimanche d’octobre → fin heure d’été
  if (month == 10 && (day - weekday) < 25) return true;
  return false;
}

void setup() {
  Serial.begin(115200);
  display.setBrightness(0x0a);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }

  Serial.println("\nWiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  timeClient.begin();
}

void loop() {
  timeClient.update();

  // Récupère l’heure brute UTC
  unsigned long rawTime = timeClient.getEpochTime();
  setTime(rawTime); // Utilise TimeLib pour extraire jour/mois/semaine

  // Calcule l’offset selon heure d’été
  int offset = isDaylightSaving(day(), month(), weekday()) ? 2 * 3600 : 1 * 3600;
  timeClient.setTimeOffset(offset);

  // Recalcule l’heure locale
  timeClient.update();
  uint8_t hours = timeClient.getHours();
  uint8_t minutes = timeClient.getMinutes();
  uint8_t seconds = timeClient.getSeconds();

  // Luminosité selon l’heure
  display.setBrightness((hours >= 7 && hours < 18) ? 0x0f : 0x07);

  // Clignotement des deux points
  uint8_t colonState = (seconds % 2 == 0) ? 0b11100000 : 0b00000000;
  display.showNumberDecEx(hours * 100 + minutes, colonState, true);

  Serial.println((String)hours + ":" + minutes + ":" + seconds);
  delay(1000);
}



Code Simple Countdown Timer

Compte à rebours (30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19)

Bibliotheque : https://github.com/avishorp/TM1637
Source : https://arduinoyard.com/tm1637-display-with-arduino/

Testé avec :

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG 4-Digital Display recto.jpg

Grove Base for XIAO (Port D1) ✅
XIAO-ESP32S3
4-Digital Display

Le résultat : (30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19)

Grove Base for XIAO 1.PNG XIAO RA4M1 4.PNG 4-Digital Display recto.jpg

Grove Base for XIAO (Port D2) ✅
XIAO-RA4M1
4-Digital Display

// TM1637 Display with Arduino - Countdown Timer
#include <TM1637Display.h>

#define CLK 2
#define DIO 3

TM1637Display display(CLK, DIO);

void setup() {
  display.setBrightness(7);
}

void loop() {
  for (int i = 30; i >= 0; i--) {
    display.showNumberDec(i, true);  // Display with leading zero (e.g., 09)
    delay(1000);
  }
  
  display.clear();
  delay(2000);
}

Code - TM1637 Display - Full Test

Le code est executé une seule fois, reset pour faire à nouveau
Source : https://arduinoyard.com/tm1637-display-with-arduino

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG 4-Digital Display recto.jpg

Grove Base for XIAO (Port D1) ✅
XIAO-ESP32S3
4-Digital Display

// TM1637 Display with Arduino - Full Test
#include <TM1637Display.h>

// Define TM1637 module connection pins (Digital Pins)
#define CLK 2  // Clock Pin
#define DIO 3  // Data Pin

// Delay time between different test cases
#define TEST_DELAY 2000  

// Custom segment encoding for displaying "DONE"
const uint8_t SEG_DONE[] = {
  SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,           // d
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
  SEG_C | SEG_E | SEG_G,                           // n
  SEG_A | SEG_D | SEG_E | SEG_F | SEG_G            // E
};

// Create display object
TM1637Display display(CLK, DIO);

void setup() {
  // Set brightness level (0x0F = max brightness)
  display.setBrightness(0x0F);
}

void loop() {
  int k;
  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff }; // All segments ON
  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 }; // All segments OFF

  // 1. Display all segments ON
  display.setSegments(data);
  delay(TEST_DELAY);

  // 2. Display numbers 0123
  data[0] = display.encodeDigit(0);
  data[1] = display.encodeDigit(1);
  data[2] = display.encodeDigit(2);
  data[3] = display.encodeDigit(3);
  display.setSegments(data);
  delay(TEST_DELAY);

  // 3. Display partial digits
  display.clear();
  display.setSegments(data + 2, 2, 2); // Display "23__"
  delay(TEST_DELAY);

  display.clear();
  display.setSegments(data + 2, 2, 1); // Display "_23_"
  delay(TEST_DELAY);

  display.clear();
  display.setSegments(data + 1, 3, 1); // Display "_123"
  delay(TEST_DELAY);

  // 4. Show numbers with and without leading zeros
  display.showNumberDec(0, false);  // Expect: ___0
  delay(TEST_DELAY);
  display.showNumberDec(0, true);   // Expect: 0000
  delay(TEST_DELAY);
  display.showNumberDec(301, false); // Expect: _301
  delay(TEST_DELAY);
  display.showNumberDec(301, true);  // Expect: 0301
  delay(TEST_DELAY);

  // 5. Display negative numbers
  display.showNumberDec(-1, false);  // Expect: __-1
  delay(TEST_DELAY);
  display.showNumberDec(-12);        // Expect: _-12
  delay(TEST_DELAY);
  display.showNumberDec(-999);       // Expect: -999
  delay(TEST_DELAY);

  // 6. Show hexadecimal numbers
  display.showNumberHexEx(0xf1af);        // Expect: f1Af
  delay(TEST_DELAY);
  display.showNumberHexEx(0x2c);          // Expect: __2C
  delay(TEST_DELAY);
  display.showNumberHexEx(0xd1, 0, true); // Expect: 00d1
  delay(TEST_DELAY);

  // 7. Display all possible dot positions
  for (k = 0; k <= 4; k++) {
    display.showNumberDecEx(0, (0x80 >> k), true);
    delay(TEST_DELAY);
  }

  // 8. Brightness test (gradual increase)
  for (k = 0; k < 4; k++) {
    data[k] = 0xff; // All segments ON
  }
  for (k = 0; k < 7; k++) {
    display.setBrightness(k);
    display.setSegments(data);
    delay(TEST_DELAY);
  }

  // 9. On/Off Test
  for (k = 0; k < 4; k++) {
    display.setBrightness(7, false);  // Turn off
    display.setSegments(data);
    delay(TEST_DELAY);
    display.setBrightness(7, true);   // Turn on
    display.setSegments(data);
    delay(TEST_DELAY);
  }

  // 10. Display "DONE"
  display.setSegments(SEG_DONE);

  // Halt execution
  while (1);
}

Liens internes

Main page


Liens externes

https://www.seeedstudio.com/Grove-4-Digit-Display.html shop

http://wiki.seeedstudio.com/Grove-4-Digit_Display wiki