Time jump on LED Matrix and matrix portal

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tolisn
 
Posts: 15
Joined: Mon Feb 06, 2023 3:12 am

Time jump on LED Matrix and matrix portal

Post by tolisn »

Hi. I have the following code the gets the time from an NTP server and shows it on the LED matrix using the Matrix portal. The time shows up OK on the matrix and then jumps a few line upward, after that everything works.

ps. Is there anyway to post a video ?


Code: Select all

#include <Adafruit_Protomatter.h>
#include <Fonts/FreeSansBold18pt7b.h> // Large friendly font
#include <Fonts/FreeSerifItalic9pt7b.h>
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include "secrets.h"

//more colors at http://www.barth-dev.de/online/rgb565-color-picker/
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF

#if defined(_VARIANT_MATRIXPORTAL_M4_) // MatrixPortal M4
  uint8_t rgbPins[]  = {7, 8, 9, 10, 11, 12};
  uint8_t addrPins[] = {17, 18, 19, 20, 21};
  uint8_t clockPin   = 14;
  uint8_t latchPin   = 15;
  uint8_t oePin      = 16;
#endif

Adafruit_Protomatter matrix(
  64,          // Width of matrix (or matrices, if tiled horizontally)
  6,           // Bit depth, 1-6
  1, rgbPins,  // # of matrix chains, array of 6 RGB pins for each
  4, addrPins, // # of address pins (height is inferred), array of pins
  clockPin, latchPin, oePin, // Other matrix control pins
  true,       // No double-buffering here (see "doublebuffer" example)
  -2);         // Row tiling: two rows in "serpentine" path

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

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

  // Connect to Wi-Fi network
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Initialize matrix...
  ProtomatterStatus status = matrix.begin();
  Serial.print("Protomatter begin() status: ");
  Serial.println((int)status);
  if(status != PROTOMATTER_OK) {
    // DO NOT CONTINUE if matrix setup encountered an error.
    for(;;);
  }

  // Set up time client
  timeClient.begin();
  timeClient.setTimeOffset(10800); // set the time zone offset (in seconds) from UTC

 // matrix.setCursor(10, 32); // set the cursor position
 // matrix.setTextColor(BLUE); // set the text color
 // matrix.println("ADAFRUIT"); // print the text

//  matrix.show();  // and show it

  //delay(5000);
  //Serial.println("TEST");
}

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

  // Format the time as a string in 12-hour format
  String formattedTime = timeClient.getFormattedTime();
  int hour = timeClient.getHours();
  if (hour > 12) {
    hour = hour - 12;
  } else if (hour == 0) {
    hour = 12;
  }
  formattedTime = String(hour) + timeClient.getFormattedTime().substring(2);

  // Display the time on the matrix display
  matrix.fillScreen(0); // clear the screen
  matrix.setCursor(5, 15); // set the cursor position
  matrix.setFont(&FreeSerifItalic9pt7b); // Use nice bitmap font
  matrix.setTextColor(RED); // set the text color
  matrix.print(formattedTime); // print the time
  matrix.show(); // and show it

  delay(1000); // wait for one second before updating
}

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Time jump on LED Matrix and matrix portal

Post by mikeysklar »

Is the display alignment off for the first second it appears?

You can drop us a link to a video on google drive, iCloud YouTube, instagram, etc.

User avatar
tolisn
 
Posts: 15
Joined: Mon Feb 06, 2023 3:12 am

Re: Time jump on LED Matrix and matrix portal

Post by tolisn »

Here is a link to a video on youtube that shows the problem.
https://www.youtube.com/shorts/wLhBXBEdeYQ

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Time jump on LED Matrix and matrix portal

Post by mikeysklar »

Can you change the privacy settings from private to public so I can view it?

User avatar
tolisn
 
Posts: 15
Joined: Mon Feb 06, 2023 3:12 am

Re: Time jump on LED Matrix and matrix portal

Post by tolisn »


User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Time jump on LED Matrix and matrix portal

Post by mikeysklar »

That works. I can see the video clearly and the text jump from a "bottom half" to "top half" on startup.

If you add this in the setup() function. Kind of similiar to what is commented out does this maintain the correct alignment?

Code: Select all

  matrix.fillScreen(0); // clear the screen
  matrix.setCursor(5, 15); // set the cursor position
  matrix.setFont(&FreeSerifItalic9pt7b); // Use nice bitmap font
  matrix.setTextColor(RED); // set the text color
  matrix.show(); // and show it

User avatar
tolisn
 
Posts: 15
Joined: Mon Feb 06, 2023 3:12 am

Re: Time jump on LED Matrix and matrix portal

Post by tolisn »

Yes that fixes it but I don't understand why .
Also one other thing, why does it not always connect to wifi and I have to press the RESET button for it do connect ?
The test board is located a few inches aways from the router so distance is not an issue. The serial monitor is reporting "Connecting to WiFi" but is never does. Once I press the reset button the connection is made. If I press again the RESET button the connection is lost and never made until I press again the RESET button and then the connection is made again.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Time jump on LED Matrix and matrix portal

Post by mikeysklar »

The setup() code addition I provided was just an attempt to make sure the RGBMatrix was a in a known good state before you started posting the clock time. You can now try to remove some of those lines and see which ones really matter.

The MatrixPortal not getting an IP address upon close reboots could be due to the access point having built in restrictions against providing IPs to the same MAC address in a very close time period (a security measure). You can probably figure out if it is a 1 minute, 3 minute or 5 minute delay before another DHCP lease is successful. The router log or the REPL console might have more.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”