Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default pin assignment as it was found in ESP32-HUB77-MatrixPanel-I2S-DMA #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions examples/MatrixClockNTP/MatrixClockNTP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* This example is based on SmartMatrix example MatrixClock but replaced RTC in favor of NTP time
* note: DS1307RTC lib as it is seems to even crash on ESP32, might need to check pins though ...
*
* Requires my for of the NTPClient:
* https://github.com/lefty01/NTPClient
*
* Samples for debug_print.h and wifi_mqtt_creds.h file can be found here:
* https://github.com/lefty01/mysnippez/blob/master/arduino/wifi_mqtt_creds.h
*
* Only tested on ESP32 with a 64x64 (P3) RGB Panel ... which works ;)
*
* This SmartMatrix example uses just the indexed color layer
*
*/

#include <Wire.h>
#include <Time.h>

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

#include <MatrixHardware_ESP32_V0.h>
#include <SmartMatrix.h>

#define DEBUG 1
#define NOMQTTCERTS 1
#define USE_ANDROID_AP 1
#include "debug_print.h"
#include "wifi_mqtt_creds.h"

//const long gmtOffset = 3600; // UTC to CET offset in sec Winterzeit
const long gmtOffset = 7200; // UTC to CET offset in sec Sommerzeit
// Central European Time (Frankfurt, Paris)
TimeChangeRule CEST = {Last, Sun, Mar, 2, 120}; // Central European Summer Time
TimeChangeRule CET = {Last, Sun, Oct, 3, 60}; // Central European Standard Time
//struct DateTime cur_dateTime;

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, gmtOffset, CEST, CET);

// SmartMatrix Defines
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
#define kMatrixWidth 64 // known working: 32, 64, 96, 128
#define kMatrixHeight 64 // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 24; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 2; // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate

const uint8_t kPanelType = SMARTMATRIX_HUB75_64ROW_MOD32SCAN;
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE); // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrixLayer, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
SMARTMATRIX_ALLOCATE_INDEXED_LAYER(indexedLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kIndexedLayerOptions);

//const int defaultBrightness = (100*255)/100; // full (100%) brightness
//const int defaultBrightness = (15*255)/100; // dim: 15% brightness
const int defaultBrightness = (90*255)/100; // dim: 90% brightness


const SM_RGB clockColor = {0xff, 0xff, 0xff};


String ipAddr;
String dnsAddr;
const unsigned maxWifiWaitSeconds = 60;
bool isWifiAvailable = false;


void print2digits(int number) {
if (number >= 0 && number < 10) {
DEBUG_PRINT('0');
}
DEBUG_PRINT(number);
}


int setupWifi() {
DEBUG_PRINTLN();
DEBUG_PRINTLN("Connecting to wifi");

unsigned retry_counter = 0;
WiFi.begin(wifi_ssid, wifi_pass);

while (WiFi.status() != WL_CONNECTED) {

delay(500);
DEBUG_PRINT(".");

retry_counter++;
if (retry_counter > maxWifiWaitSeconds) {
DEBUG_PRINTLN(" TIMEOUT!");
return 1;
}
}
ipAddr = WiFi.localIP().toString();
dnsAddr = WiFi.dnsIP().toString();

DEBUG_PRINTLN("");
DEBUG_PRINTLN("WiFi connected");
DEBUG_PRINTLN("IP address: ");
DEBUG_PRINTLN(ipAddr);
DEBUG_PRINTLN("DNS address: ");
DEBUG_PRINTLN(dnsAddr);

return 0;
}



void setup() {
DEBUG_BEGIN(115200);
delay(200);
DEBUG_PRINTLN("Matrix Clock Setup - NTP Version");
DEBUG_PRINTLN("-------------------");
isWifiAvailable = setupWifi() ? false : true;

timeClient.begin();
timeClient.update();


// setup matrix
matrixLayer.addLayer(&indexedLayer);
matrixLayer.begin();
matrixLayer.setBrightness(defaultBrightness);

// display a simple message - will stay on the screen if calls to the RTC library fail later
indexedLayer.fillScreen(0);
indexedLayer.setFont(font3x5); //gohufont11); // apple3x5
indexedLayer.drawString(0, kMatrixHeight / 2 - 6, 1, "CLOCK");
indexedLayer.swapBuffers(false);

// print network info ...
indexedLayer.drawString(0, kMatrixHeight / 2 + 6, 1, ipAddr.c_str());

delay(3000);
}

void loop() {
int x = kMatrixWidth/2-22;

bool rc = timeClient.update();

// output time to console
DEBUG_PRINT("Ok, Time = ");
DEBUG_PRINTLN(timeClient.getFormattedTime());
DEBUG_PRINT("Ok, Date = ");
DEBUG_PRINTLN(timeClient.getFormattedDate());

// clear screen before writing new text
indexedLayer.fillScreen(0);

/* Draw Clock to SmartMatrix */
uint8_t hour = timeClient.getHours(); //cur_dateTime.dt_hours;
if (hour > 12)
hour -= 12;

if (hour < 10) // move to right if double digit hour
x += 3;

indexedLayer.setFont(gohufont11b);
indexedLayer.drawString(x, kMatrixHeight / 2 - 10, 1, timeClient.getFormattedTime().c_str());
indexedLayer.drawString(x, kMatrixHeight / 2 + 10, 1, timeClient.getFormattedDate().c_str());

indexedLayer.swapBuffers();

delay(1000);
}

25 changes: 25 additions & 0 deletions src/MatrixHardware_ESP32_V0.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define ESP32_JC_RIBBON_PINOUT_WEMOS 8
#define HUB75_ADAPTER_LITE_V0_PINOUT 9
#define ESP32_RGB64x32MatrixPanel_I2S_DMA_DEFAULT 10
#define ESP32_RGB64x64MatrixPanel_I2S_DMA_DEFAULT 11

#ifndef GPIOPINOUT
#define GPIOPINOUT ESP32_FORUM_PINOUT
Expand Down Expand Up @@ -492,6 +493,30 @@
// this pin can be manually toggled when the latch pin is high to send CLK pulses to the panel (noramlly latch blocks clock)
#define CLK_MANUAL_PIN GPIO_NUM_22

#elif (GPIOPINOUT == ESP32_RGB64x64MatrixPanel_I2S_DMA_DEFAULT)
// from ESP32-HUB75-MatrixPanel-I2S-DMA.h
#pragma message "MatrixHardware: ESP32-HUB75-MatrixPanel-I2S-DMA.h Default pinout for 64x64 with E pin"

#define CLKS_DURING_LATCH 0
#define MATRIX_I2S_MODE I2S_PARALLEL_BITS_16
#define MATRIX_DATA_STORAGE_TYPE uint16_t

#define R1_PIN GPIO_NUM_25
#define G1_PIN GPIO_NUM_26
#define B1_PIN GPIO_NUM_27
#define R2_PIN GPIO_NUM_14
#define G2_PIN GPIO_NUM_12
#define B2_PIN GPIO_NUM_13

#define A_PIN GPIO_NUM_23
#define B_PIN GPIO_NUM_19
#define C_PIN GPIO_NUM_5
#define D_PIN GPIO_NUM_17
#define E_PIN GPIO_NUM_32
#define LAT_PIN GPIO_NUM_4
#define OE_PIN GPIO_NUM_15
#define CLK_PIN GPIO_NUM_16

#endif

//#define DEBUG_PINS_ENABLED
Expand Down