Close
0%
0%

Date Counter

A 10x10 LED matrix displays the current day of the month with a color transition from red to green as the days progress.

Similar projects worth following
Greetings everyone and welcome back, and here's something exciting.

The Date Counter is a Raspberry Pi Pico W-based matrix board that uses data from an NTP client to display the current date on an RGB matrix.
This date counter, similar to a clock, displays the current day of the month. It's a fun and eye-catching device to keep track of the date, with the extra bonus of the color changing from red to green as the days pass. It isn't as precise as a clock with hours, minutes, and seconds, but it does provide a clear daily indication of where you are in the month.

This date counter, similar to a clock, displays the current day of the month. It's a fun and eye-catching device to keep track of the date, with the extra bonus of the color changing from red to green as the days pass. It isn't as precise as a clock with hours, minutes, and seconds, but it does provide a clear daily indication of where you are in the month.

Our goal for this project was to develop a basic desk date clock that tells us what day it is; it begins with RED and turns to green as the day progresses, signaling the end of the month.

This project is basically version 1 of a future Matrix Clock project, which i will be preparing in the upcoming months.

Matrix Design

For this project, we are utilizing one of our previous matrix projects, which was a matrix with a dedicated microcontroller board (Raspberry Pi PICO) that could be utilized for future RGB matrix-based projects that include our date counter.

https://www.instructables.com/Raspberry-Pi-Pico-Matrix-Project/

The two main components of this project's circuit are the LED matrix itself, which is made up of 100 WS2812B LEDs connected in their standard format, connecting the first LED's dout to the second's din, the second LED's dout to the second's din, and so on until the hundredth LED. The VCC and GND of each LED are connected in parallel.

The second component of the circuit is a Raspberry Pi Pico W. The first LED Din is attached to the Raspberry Pi Pico's GPIO D0. We put a USB Type-C port alongside Pico's 5V IN and GND connectors to power the board using a type-C connector.

We put 100 decoupling capacitors to each WS2812B LED, but in the end, we only used 10x 100 nF capacitors, one for each row.

Once the design was finished, we saved it as a board file and put all 100 LEDs in a 10x10 row and column grid.

Please take note that the LEDs D1 through D10 are placed in a single row. D11 appears at the start of the new column and extends to D20, followed by D21, which appears at the start of the next column and extends to D100. This is also known as the serpentine matrix or snake matrix pattern.

After setting up the PCB and installing the Pico and all SMD components, we exported the Gerber data, which will be sent to a PCB manufacturer for samples.

HQ NextPCB Service

After completing the PCB design, we export the Gerber data and send it to HQ NextPCB for samples.

For the mid and top layer boards, two orders were placed. We ordered a black Solder mask with white screen for the mid- and top-layer boards.

After placing the order, the PCBs were received within a week, and the PCB quality was pretty great.

In addition, I have to bring in HQDFM to you, which helped me a lot through many projects. Huaqiu’s in-house engineers developed the free Design for Manufacturing software, HQDFM, revolutionizing how PCB designers visualize and verify their designs.

Take advantage of NextPCB's Accelerator campaign and get 2 free assembled RP2040-based PCBs for your innovative projects.

https://www.nextpcb.com/blog/rp2040-free-pcba-prototypes-nextpcb-accelerator

This offer covers all costs, including logistics, making it easier and more affordable to bring your ideas to life. SMT services can be expensive, but NextPCB is here to help you overcome that hurdle. Simply share your relevant project, and they'll take care of the rest. Don't miss out on this amazing opportunity to advance your tech creations!

HQDFM: Free Online Gerber Viewer and DFM Analysis Tool

Also, NextPCB has its own Gerber Viewer and DFM analysis software.

Your designs are improved by their HQDFM software (DFM) services. Since I find it annoying to have to wait around for DFM reports from manufacturers, HQDFM is the most efficient method for performing a pre-event self-check.

Here is what online Gerber Viewer shows me. Would not be more clear. However, for full function, like DFM analysis for PCBA, you need to download the software. The online version only provides a simple PCB DFM report.

With...

Read more »

  • 1
    PCB Assembly
    • Using a solder paste dispenser needle, we apply solder paste to each component pad to begin the circuit assembly process. In this case, we are using 63/37 SnPB Solderpaste.
    • After that, we pick each WS2812B LED and place it into their correct position.
    • The PCB is then heated from below to the solder paste melting temperature by placing the circuit on the Reflow Hotplate, which causes all of the SMD LEDs to be connected to their pads.
    • After reflow, we place the THT components, which consist of a female header pin connector for the Raspberry Pi Pico W and a USB-type C port.
    • Using a soldering iron, we solder the leads of every through-hole component from the bottom side of the board.
    • At last, we installed the Raspberry Pi PICO W on the header pins and our PCB assembly process is complete.
  • 2
    DEMO TEST CODE

    For the Demo test sketch for this project, we created a number counter sketch that counts from 1 to 30 with a one-second interval. We added a feature to this test code that causes a color shift from red to green.

    #include <Adafruit_NeoPixel.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_NeoMatrix.h>
    
    #define MATRIX_PIN 12 // GPIO pin connected to the LED matrix data pin
    #define MATRIX_WIDTH 10
    #define MATRIX_HEIGHT 10
    Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_PIN,
      NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
      NEO_MATRIX_ROWS,
      NEO_GRB + NEO_KHZ800);
    
    void setup() {
      Serial.begin(115200);
      Serial.println("Starting color fade test...");
    
      // Initialize matrix
      matrix.begin();
      matrix.setTextWrap(false);
      matrix.setBrightness(50);
      matrix.setRotation(3); // Rotate the text 90 degrees in the opposite direction
    }
    
    void loop() {
      for (int i = 1; i <= 30; i++) {
        // Calculate the color based on the day of the month
        int r = 255 - ((i - 1) * 255 / 30); // Red decreases
        int g = (i - 1) * 255 / 30; // Green increases
        int color = matrix.Color(r, g, 0);
    
        // Display the day number on the LED matrix with the calculated color
        matrix.fillScreen(0); // Clear screen
        matrix.setTextSize(1); // Set text size to fit within 10x10 matrix
        matrix.setTextColor(color);
    
        String dayStr = String(i); // Convert day to string
    
        if (dayStr.length() < 2) {
          matrix.setCursor((matrix.width() - 6) / 2, (matrix.height() - 8) / 2);
        } else {
          matrix.setCursor((matrix.width() - 12) / 2, (matrix.height() - 8) / 2);
        }
    
        matrix.print(dayStr);
        matrix.show();
    
        Serial.print("Displaying day: "); Serial.print(dayStr); Serial.print(" with color: ");
        Serial.print("R="); Serial.print(r); Serial.print(", G="); Serial.println(g);
    
        delay(1000); // Update every second
      }
    }

    Here, we begin the month with a red color and as the days pass and we approach 30, the color changes from red to green.

    Make sure you install the required libraries: Prior to using this sketch, install Adafruit NeoPixel, Adafruit GFX, and Adafruit NeoMatrix.

  • 3
    MAIN CODE

    After testing the demo test code, let's have a look at the main code for this project and its a simple one.

    #include <WiFi.h>
    #include <NTPClient.h>
    #include <WiFiUdp.h>
    #include <Adafruit_NeoPixel.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_NeoMatrix.h>
    #include <time.h>
    
    // WiFi credentials
    const char* ssid = "UR SSID";
    const char* password = "UR PASS";
    
    // Define NTP Client to get time
    WiFiUDP ntpUDP;
    NTPClient timeClient(ntpUDP, "pool.ntp.org", 19800, 60000); // IST is UTC+5:30 or 19800 seconds
    
    // Define LED matrix
    #define MATRIX_PIN 12 // GPIO pin connected to the LED matrix data pin
    #define MATRIX_WIDTH 10
    #define MATRIX_HEIGHT 10
    Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_PIN,
      NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
      NEO_MATRIX_ROWS,
      NEO_GRB + NEO_KHZ800);
    
    void setup() {
      Serial.begin(115200);
      Serial.println("Setting up WiFi and NTP...");
    
      // Initialize matrix
      matrix.begin();
      matrix.setTextWrap(false);
      matrix.setBrightness(50);
      matrix.setRotation(3); // Rotate the text 90 degrees in the opposite direction
    
      // Connect to WiFi
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("WiFi connected.");
    
      // Initialize NTPClient
      timeClient.begin();
    }
    
    void loop() {
      timeClient.update();
    
      // Get current date and time from NTP client
      time_t rawTime = timeClient.getEpochTime();
      struct tm *timeInfo = localtime(&rawTime);
    
      // Extract the current day of the month
      int currentDay = timeInfo->tm_mday;
      String dayStr = String(currentDay); // Convert day to string
    
      // Calculate the color based on the day of the month
      int r = 255 - ((currentDay - 1) * 255 / 30); // Red decreases
      int g = (currentDay - 1) * 255 / 30; // Green increases
      int color = matrix.Color(r, g, 0);
    
      // Display the day number on the LED matrix with the calculated color
      matrix.fillScreen(0); // Clear screen
      matrix.setTextSize(1); // Set text size to fit within 10x10 matrix
      matrix.setTextColor(color);
    
      if (dayStr.length() < 2) {
        matrix.setCursor((matrix.width() - 6) / 2, (matrix.height() - 8) / 2);
      } else {
        matrix.setCursor((matrix.width() - 12) / 2, (matrix.height() - 8) / 2);
      }
    
      matrix.print(dayStr);
      matrix.show();
    
      delay(1000); // Update every second
    }

    Our code is intended to display the current day of the month on an LED matrix, with a color transition from red to green as the days progress. The script begins by importing the following libraries: WiFi, NTPClient, and WiFiUdp for managing WiFi connections and retrieving time from the NTP server; and Adafruit_NeoPixel, Adafruit_GFX, and Adafruit_NeoMatrix for controlling the LED matrix.

    An NTP client is instantiated to retrieve the current time from the "pool.ntp.org" NTP server, with an offset for Indian Standard Time (UTC+5:30).

    The LED matrix is configured with a pin defined for GPIO 12, dimensions of 10x10, and specified connection and color order.

    In the setup() function, serial communication is initiated for debugging purposes. The LED matrix is initialized with specified settings, including brightness and text rotation. The script then attempts to connect to the WiFi network using the provided credentials, waiting until the connection is established. Once connected, the NTP client is started to begin retrieving the current time.

    In the loop() function, the NTP client is updated to retrieve the most recent time from the NTP server. The current date and time are retrieved and stored as a struct tm object. The current day of the month is then extracted and transformed into a string. The color used to represent the day is determined by the day of the month, transitioning from red on the first to green on the 30th or 31st. The LED matrix is then cleared, and the current day is printed in the calculated color, centering on the matrix. The display is refreshed every second to ensure that it is up to date.

View all 4 instructions

Enjoy this project?

Share

Discussions

Does this project spark your interest?

Become a member to follow this project and never miss any updates