Max7219

Forum dédié aux bricolages d'objets connectés IOT et leurs communications avec DomoticZ :
- Remplacement de firmware des prises, modules relais ...
- Fabrication à base d'ESP8266, de NodeMCU, de Weemos et consorts ...
dokho
Messages : 685
Inscription : 28 déc. 2014, 19:32

Max7219

Message par dokho »

Bonsoir,

Quelqu'un utilise-t-il un affichage à base de max7219 piloté par un esp ?

Je souhaiterais faire un affichage intérieur afin d'afficher différentes info venant de domoticz (conso, température,...)

Je ne trouve pas grand chose sur le net à ce sujet :(


Envoyé de mon SM-N9005 en utilisant Tapatalk
Jeff
Messages : 1007
Inscription : 17 nov. 2016, 20:54
Localisation : Rennes (35)

Re: Max7219

Message par Jeff »

Non moi j'utilise les écrans Nextion, affichage et pilotage, ça claque ;)
https://easydomoticz.com/forum/viewtopi ... =24&t=3731

J'avais trouvé cela qui se rapproche plus de ce que tu cherches mais dur dur !
http://faire-ca-soi-meme.fr/domotique/2 ... 6-arduino/
Version: 2023.1 sur VM Synology, docker Zwave Js UI (Z-stick GEN5, Fibaro...), Zigbeefordomoticz. Nextion RGB Led Screen
dokho
Messages : 685
Inscription : 28 déc. 2014, 19:32

Re: Max7219

Message par dokho »

Salut,
J'avais vu ton topic sur les écrans Nextion, j'attends que le mien arrive :)

Ce que je souhaite faire avec les Max7219 c'est juste un petit affichage informatif.
J'ai trouvé un truc à base d'esp et d'arduino mini qui permet d'afficher les infos d'un topic mqtt, il faut que je teste ça :)

Envoyé de mon SM-N9005 en utilisant Tapatalk
Jeff
Messages : 1007
Inscription : 17 nov. 2016, 20:54
Localisation : Rennes (35)

Re: Max7219

Message par Jeff »

Tu nous monteras le résultat ca peut être sympa, c'est sympa ces affichages :)
Pour nextion j'ai pas mal progressé, juste le besoin qui manque, faire pour faire ... n'hésite pas à demander à l'occasion !
Version: 2023.1 sur VM Synology, docker Zwave Js UI (Z-stick GEN5, Fibaro...), Zigbeefordomoticz. Nextion RGB Led Screen
dokho
Messages : 685
Inscription : 28 déc. 2014, 19:32

Re: Max7219

Message par dokho »

J'avance difficilement, j'ai un peu de mal à comprendre cette programmation donc je pioche dans des exemples pour arriver à mes fins.

Le montage n'est pas fait pour l'instant mais niveau affichage ça ressemble à ca: https://youtu.be/JgXon5tdc5U

A suivre.
Jeff
Messages : 1007
Inscription : 17 nov. 2016, 20:54
Localisation : Rennes (35)

Re: Max7219

Message par Jeff »

Yesss j'adore :D , tu passes par un plugin espeasy ou tu as tout fait en arduino ?
J'avais trouvé cela a l'époque, trop dur et pas compatible avec domoticz.
http://faire-ca-soi-meme.fr/domotique/2 ... 6-arduino/
Version: 2023.1 sur VM Synology, docker Zwave Js UI (Z-stick GEN5, Fibaro...), Zigbeefordomoticz. Nextion RGB Led Screen
dokho
Messages : 685
Inscription : 28 déc. 2014, 19:32

Re: Max7219

Message par dokho »

J'ai trouvé un sketch pour esp qui créé un webserver que j'alimente via curl.

C'est du bidouillage, je pense même qu'on pourrait dire que c'est sale comme code, mais ça fonctionne :)

Je posterais le code demain quand je serais rentré (des fois que ça intéresse quelqu'un)


Envoyé de mon SM-N9005 en utilisant Tapatalk
Jeff
Messages : 1007
Inscription : 17 nov. 2016, 20:54
Localisation : Rennes (35)

Re: Max7219

Message par Jeff »

Super, je suis bon pour faire une commande d'un bloc de 4 !
J'attends ton code et je regarderais avec le code que je t'ai mis...si j'en fait quelque chose, du pure geek :ugeek:
Version: 2023.1 sur VM Synology, docker Zwave Js UI (Z-stick GEN5, Fibaro...), Zigbeefordomoticz. Nextion RGB Led Screen
dokho
Messages : 685
Inscription : 28 déc. 2014, 19:32

Re: Max7219

Message par dokho »

Voici le code que j'utilise.

Je préfère prévenir: il est vraiment crado, c'est du bidouillage :)

Code : Tout sélectionner

/* ESP8266 plus MAX7219 LED Matrix that displays messages revecioved via a WiFi connection using a Web Server
 Provides an automous display of messages
 The MIT License (MIT) Copyright (c) 2017 by David Bird.
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, but not sub-license and/or 
 to sell copies of the Software or to permit persons to whom the Software is furnished to do so, subject to the following conditions: 
   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
See more at http://dsbird.org.uk
*/

//################# LIBRARIES ##########################
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
//#include <WiFiClient.h>
#include <WiFiManager.h>     // https://github.com/tzapu/WiFiManager
#include <DNSServer.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
#include <time.h>

//TEST
#include <TimeLib.h>
#include <NtpClientLib.h>
//TEST


int pinCS = D4; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 9;
int numberOfVerticalDisplays   = 1;
char time_value[20];
String temperature_maison, webpage, consommation_maison, message, text, intro, heure;

//################# DISPLAY CONNECTIONS ################
// LED Matrix Pin -> ESP8266 Pin
// Vcc            -> 3v  (3V on NodeMCU 3V3 on WEMOS)
// Gnd            -> Gnd (G on NodeMCU)
// DIN            -> D7  (Same Pin for WEMOS)
// CS             -> D4  (Same Pin for WEMOS)
// CLK            -> D5  (Same Pin for WEMOS)

//################ PROGRAM SETTINGS ####################
String version = "v2.0";       // Version of this program
ESP8266WebServer server(80); // Start server on port 80 (default for a web-browser, change to your requirements, e.g. 8080 if your Router uses port 80
                               // To access server from the outside of a WiFi network e.g. ESP8266WebServer server(8266) add a rule on your Router that forwards a
                               // connection request to http://your_network_ip_address:8266 to port 8266 and view your ESP server from anywhere.
                               // Example http://yourhome.ip:8266 will be directed to http://192.168.0.40:8266 or whatever IP address your router gives to this server
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
int wait   = 6000; // In milliseconds between scroll movements
int spacer = 1;
int width  = 5 + spacer; // The font width is 5 pixels
int length;
int count=0;
String SITE_WIDTH =  "1000";
unsigned long previousMillis = 0;



void setup() {
  Serial.begin(115200); // initialize serial communications
  WiFiManager wifiManager;
  // New OOB ESP8266 has no Wi-Fi credentials so will connect and not need the next command to be uncommented and compiled in, a used one with incorrect credentials will
  // so restart the ESP8266 and connect your PC to the wireless access point called 'ESP8266_AP' or whatever you call it below in ""
  // wifiManager.resetSettings(); // Command to be included if needed, then connect to http://192.168.4.1/ and follow instructions to make the WiFi connection
  // Set a timeout until configuration is turned off, useful to retry or go to sleep in n-seconds
  wifiManager.setTimeout(180);
  //fetches ssid and password and tries to connect, if connections succeeds it starts an access point with the name called "ESP8266_AP" and waits in a blocking loop for configuration
  if(!wifiManager.autoConnect("ESP8266_AP")) {
    Serial.println(F("failed to connect and timeout occurred"));
    delay(6000);
    ESP.reset(); //reset and try again
    delay(180000);
  }
  // At this stage the WiFi manager will have successfully connected to a network, or if not will try again in 180-seconds
  Serial.println(F("WiFi connected..."));



  
  //----------------------------------------------------------------------
  server.begin(); Serial.println(F("Webserver started...")); // Start the webserver  configTime(0 * 3600, 0, "pool.ntp.org", "time.nist.gov");
  matrix.setIntensity(2);    // Use a value between 0 and 15 for brightness
  matrix.setRotation(0, 0);  // The first display is position upside down
  matrix.setRotation(1, 0);  // The first display is position upside down
  matrix.setRotation(2, 0);  // The first display is position upside down
matrix.setRotation(3, 0);  // The first display is position upside down
matrix.setRotation(4, 0);  // The first display is position upside down 
matrix.setRotation(5, 1);  // The first display is position upside down
matrix.setRotation(6, 1);  // The first display is position upside down
matrix.setRotation(7, 1);  // The first display is position upside down
matrix.setRotation(8, 1);  // The first display is position upside down 


  server.on("/", GetMessage);
  wait    = 40;
  intro = "Domoticz Infos";
  display_scroll(intro); // Display the message
  wait    = 75;
  //display_scroll(message); // Display the message
  //message = "Waiting data...";
  //wait    = 100;


//TEST
NTP.begin("pool.ntp.org", 1, true);
NTP.setInterval(600);
//TEST

  
}

void loop() {
  unsigned long currentMillis = millis();
  server.handleClient();
 if (currentMillis - previousMillis >= 1000) {
    previousMillis = currentMillis;
    count++; //Seconds
  }
 
  
  
if (server.args() < 1 ) { 
  display_scroll("Waiting data...");
  count=0;


//TEST
//Serial.print(hour());
//  printDigits(minute());
//  Serial.println();
//display_static(hour() + ":" + minute());
//delay(5000);
//TEST
    
  
 }
 else if (message.length() == 0 && count>=0 && count <1 && consommation_maison.length() > 0 ){ 
 //display_static(" "); 
 display_scroll("Consomation"); // Display the message
 Serial.println(count);
 }
 else if (message.length() == 0 && count>=1 && count<6 && consommation_maison.length() > 0){
 display_static(consommation_maison);
 Serial.println(count);
 }
 else if (message.length() == 0 && count>=6 && count <7 && temperature_maison.length() > 0){ 
 //display_scroll(" "); 
 display_scroll("Temperature"); // Display the message
 Serial.println(count);
 }
 else if (message.length() == 0 && count>=7 && count<12 && temperature_maison.length() > 0){
 display_static(temperature_maison);
 Serial.println(count);
 }
 else if (message.length() == 0 && count>=12 && count<13 && heure.length() > 0){ 
 display_scroll(" ");
 Serial.println(count);
 }
 else if (message.length() == 0 && count>=13 && count<23 && heure.length() > 0){ 
 display_static(heure);
 Serial.println(count);
 }
 else if (message.length() == 0 && count>=22 && temperature_maison.length() > 0){
    count=0; //<----reset
    Serial.println(count);
 }
 else if (message.length() >0){
  display_scroll(message);
  consommation_maison = "";
  temperature_maison = "";
 }
}

//TEST
//void printDigits(int digits)
//{
  // utility for digital clock display: prints preceding colon and leading 0
//  Serial.print(":");
//  if (digits < 10)
//   Serial.print('0');
//  Serial.print(digits);
//}
//TEST





void display_scroll(String message){
   for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) {
    //matrix.fillScreen(LOW);
    int letter = i / width;
    int x = (matrix.width() - 1) - i % width;
    int y = (matrix.height() - 8) / 2; // center the text vertically
    while ( x + width - spacer >= 0 && letter >= 0 ) {
      if ( letter < message.length() ) {
        matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background OFF, reverse these to invert the display!
      }
      letter--;
      x -= width;
    }
    matrix.write(); // Send bitmap to display
delay(wait/2);
//  length = message.length() * width;
//    //fill with blank spaces the rest of the display area
//    for (int i = 8; i>0; i--){
//      message += " ";
//    }
//    matrix.setCursor((numberOfHorizontalDisplays*8-length)/2,0); // Center text 
//    matrix.fillScreen(LOW);
//    matrix.print(message);
//    matrix.write();
  }
}

void display_static(String text){
length = text.length() * width;
    //fill with blank spaces the rest of the display area
    for (int i = 8; i>0; i--){
      text += " ";
    }
    matrix.setCursor((numberOfHorizontalDisplays*8-length)/2,0); // Center text 
    matrix.fillScreen(LOW);
    matrix.print(text);
    matrix.write();
  
}
void GetMessage() {
  webpage = ""; // don't delete this command, it ensures the server works reliably!
  append_page_header();
  String IPaddress = WiFi.localIP().toString();
  webpage += "<form action=\"http://"+IPaddress+"\" method='post'>";
  webpage += "<P>Enter message: <INPUT type='text' size ='60' name='message' value='Enter message'></P></form><br>";
  //webpage += "<P>Enter consommation: <INPUT type='text' size ='60' name='consommation' value='Enter consommation'></P></form><br>";
  append_page_footer();
  server.send(200, "text/html", webpage); // Send a response to the client to enter their inputs, if needed, Enter=defaults
  if (server.args() > 0 ) { // Arguments were received
    for ( uint8_t i = 0; i  <= server.args(); i++ ) {
      String Argument_Name   = server.argName(i);
      String client_response = server.arg(i);
      if (Argument_Name == "temperature_maison") temperature_maison = client_response;
      if (Argument_Name == "consommation_maison") consommation_maison = client_response;
      if (Argument_Name == "message") message = client_response;
      if (Argument_Name == "heure") heure = client_response;
    }
  }
}

void append_page_header() {
  webpage  = F("<!DOCTYPE HTML><html lang='en'><head>"); // Change language (en) as required
  webpage += "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>";
  webpage += F("<title>Message Board</title><style>");
  webpage += F("body {width:");
  webpage += SITE_WIDTH;
  webpage += F("px;margin:0 auto;font-family:arial;font-size:14px;text-align:center;color:#cc66ff;background-color:#F7F2Fd;}");
  webpage += F("ul{list-style-type:circle; margin:0;padding:0;overflow:hidden;background-color:#d8d8d8;font-size:14px;}");
  webpage += F("li{float:left;border-right:1px solid #bbb;}last-child {border-right:none;}");
  webpage += F("li a{display: block;padding:2px 12px;text-decoration:none;}");
  webpage += F("li a:hover{background-color:#FFFFFF;}");
  webpage += F("section {font-size:16px;}");
  webpage += F("p {background-color:#E3D1E2;font-size:16px;}");
  webpage += F("div.header,div.footer{padding:0.5em;color:white;background-color:gray;clear:left;}");
  webpage += F("h1{background-color:#d8d8d8;font-size:26px;}");
  webpage += F("h2{color:#9370DB;font-size:22px;line-height:65%;}");
  webpage += F("h3{color:#9370DB;font-size:16px;line-height:55%;}");
  webpage += F("</style></head><body><h1>Message Display Board ");
  webpage += version+"</h1>";
}

void append_page_footer(){ // Saves repeating many lines of code for HTML page footers
  webpage += F("<ul><li><a href='/'>Enter Message</a></li></ul>");
  webpage += "&copy;"+String(char(byte(0x40>>1)))+String(char(byte(0x88>>1)))+String(char(byte(0x5c>>1)))+String(char(byte(0x98>>1)))+String(char(byte(0x5c>>1)));
  webpage += String(char((0x84>>1)))+String(char(byte(0xd2>>1)))+String(char(0xe4>>1))+String(char(0xc8>>1))+String(char(byte(0x40>>1)));
  webpage += String(char(byte(0x64/2)))+String(char(byte(0x60>>1)))+String(char(byte(0x62>>1)))+String(char(0x6e>>1));
  webpage += F("</body></html>");
}

Pour afficher heure/conso/température j'utilise:

Code : Tout sélectionner

os.execute('curl -m 5 -X POST -F "temperature_maison=' .. tempmoymaison .. ' degres" -F "consommation_maison=' .. conso_maison .. ' watts" -F "heure=' .. heure_actuelle .. ':' .. minute_actuelle ..'" http://192.168.0.4')
tempmoymaison, conso_maison et heure_actuelle sont des variables à définir via un script time.

Il est possible de n'afficher qu'un seul message qui défile à l'infini:

Code : Tout sélectionner

os.execute('curl -m 5 -X POST -F "temperature_maison=MON MESSAGE QUI DEFILE" http://192.168.0.4')
Pour revenir à l'affichage conso/température/heure il suffit de:

Code : Tout sélectionner

 
os.execute('curl -m 5 -X POST -F "temperature_maison=" http://192.168.0.4') 

Si ça peut servir à quelqu'un :)
Jeff
Messages : 1007
Inscription : 17 nov. 2016, 20:54
Localisation : Rennes (35)

Re: Max7219

Message par Jeff »

Parfait, merci :D
J'ai commandé un bloc de 4 max7219 en ligne...
Version: 2023.1 sur VM Synology, docker Zwave Js UI (Z-stick GEN5, Fibaro...), Zigbeefordomoticz. Nextion RGB Led Screen
Répondre