Hello all,
I had a project to display time and temperature by using multiple module Max7219 32 x 8 (4 in 1), DHT22 as the temperature sensor and ESP32 as the microcontroller. My plan was too used 3 max7219, 1st would be showing time and 2nd & 3rd temperature and humidity.
Now i found a problem, the 2nd & 3rd led not showing the text as i wanted. Even the third not showing anything. Even i try a simple animation just to see if its worked the connection or not.
I've read some information that some say more than 1 max7219 cannot be connected using jumper cable. but i find it odd that they got the slot for extension.
Below is the schematic diagram (just imagine there are 3 max7219 4in1)
And below is the coding
// REQUIRES the following Arduino libraries:
// - ThingSpeak library: https://github.com/mathworks/thingspeak-arduino
// - MD_Parola Library: https://github.com/MajicDesigns/MD_Parola
// - MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
// Find All "Great Projects" Videos : https://www.youtube.com/channel/UCCC8DuqicBtP3A_aC53HYDQ/videos
// Header file includes
#include <WiFi.h>
#include <time.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <SimpleDHT.h>
#include "secrets.h"
#include "Font_Data.h"
int pinDHT11 = 14;
SimpleDHT11 dht11(pinDHT11);
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 12
#define CLK_PIN 18 // or SCK
#define DATA_PIN 19 // or MOSI
#define CS_PIN 5 // or SS
// SPI hardware interface
//MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define SPEED_TIME 60
#define PAUSE_TIME 0
#define MAX_MESG 75
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
WiFiClient client;
char Message[MAX_MESG+1] = { "Happy Happy Happy" };
char WeatherTh[MAX_MESG+1] = "";
int timezone = 1;
int dst = 0;
uint16_t h, m, s;
uint8_t dow;
int day;
uint8_t month;
String year;
// Global variables
char szTime[9]; // mm:ss\0
char szsecond[4]; // ss
char szMesg[MAX_MESG+1] = "";
uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C
char *mon2str(uint8_t mon, char *psz, uint8_t len)
// Get a label from PROGMEM into a char array
{
static const char str[][10] PROGMEM =
{
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
*psz = '\0';
mon--;
if (mon < 12)
{
strncpy_P(psz, str[mon], len);
psz[len] = '\0';
}
return(psz);
}
char *dow2str(uint8_t code, char *psz, uint8_t len)
{
static const char str[][10] PROGMEM =
{
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
*psz = '\0';
code--;
if (code < 7)
{
strncpy_P(psz, str[code], len);
psz[len] = '\0';
}
return(psz);
}
void getsec(char *psz)
// Code for reading clock date
{
sprintf(psz, "%02d", s);
}
void getTime(char *psz, bool f = true)
// Code for reading clock time
{
time_t now = time(nullptr);
struct tm* p_tm = localtime(&now);
h = p_tm->tm_hour;
m = p_tm->tm_min;
s = p_tm->tm_sec;
sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
}
void getDate(char *psz)
// Code for reading clock date
{
char szBuf[10];
time_t now = time(nullptr);
struct tm* p_tm = localtime(&now);
dow = p_tm->tm_wday+1;
day = p_tm->tm_mday;
month = p_tm->tm_mon + 1;
sprintf(psz, "%d %s %04d", day, mon2str(month, szBuf, sizeof(szBuf)-1), (p_tm->tm_year + 1900));
}
void getTemperatur(char *psz)
// Code for reading clock date
{
// read without samples.
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
delay(100);
return;
}
strcpy(szMesg, "Temperature : ");
dtostrf((int)temperature, 3, 1, WeatherTh);
strcat(szMesg, WeatherTh);
strcat(szMesg, " $");
}
void getHumidit(char *psz)
// Code for reading clock date
{
// read without samples.
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
delay(100);
return;
}
strcpy(szMesg, "Humidity : ");
dtostrf((int)humidity, 3, 1, WeatherTh);
strcat(szMesg, WeatherTh);
strcat(szMesg, " % RH");
}
void setup(void)
{
Serial.begin(115200); // Initialize serial
WiFi.mode(WIFI_STA);
getTimentp();
delay(2000);
P.begin(3);
P.setInvert(false);
P.setZone(0, 0, 7);
P.setZone(1, 8, 8);
P.setZone(2, 9, 11);
P.setFont(1, numeric7Seg);
P.setFont(2, numeric7Se);
P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0, PA_PRINT, PA_SCROLL_LEFT);
P.displayZoneText(1, szsecond, PA_LEFT, SPEED_TIME, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(2, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.addChar('$', degC);
}
void loop(void)
{
static uint32_t lastTime = 0; // millis() memory
static uint8_t display = 0; // current display mode
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
// Finally, adjust the time string if we have to
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getsec(szsecond);
getTime(szTime, flasher);
flasher = !flasher;
P.displayReset(1);
P.displayReset(2);
}
if (P.getZoneStatus(0))
{
switch (display)
{
case 0: // Temperature deg C
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
getTemperatur(szMesg);
Serial.println(szMesg);
break;
case 1: // Relative Humidity
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
getHumidit(szMesg);
Serial.println(szMesg);
display++;
break;
case 2: // day of week
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
dow2str(dow, szMesg, MAX_MESG);
Serial.println(szMesg);
break;
case 3: // Date
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
getDate(szMesg);
Serial.println(szMesg);
display++;
break;
default: // Message
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
strcpy(szMesg, Message);
Serial.println(szMesg);
display = 0;
break;
}
P.displayReset(0);
}
}
void getTimentp()
{
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network.
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(200);
}
}
Serial.println("Connected");
configTime(timezone * 3600, dst, "pool.ntp.org","time.nist.gov");
while(!time(nullptr)){
Serial.print(".");
delay(100);
}
Serial.print("Time Update");
delay(2000);
}