Controllo LCD array con RTC (con sorgenti) - LCD control array with RTC (with sources)

Prova di gestione di un economico array di LCD a matrice 8x8 con lettura di un modulo RTC. I moduli a matrice LCD che ho preso sono già raggruppati a 4 e possono essere connessi altri moduli in cascata sia in senso orizzontale che verticale. La libreria utilizzata si serve della connessione SPI (Serial Peripheral Interface) per la gestione dei moduli mentre il modulo RTC usa la I2C. In internet si trovano più facilmente moduli 8x8 singoli ma questi già assemblati a 4 sono veramente comodi anche perchè sono separabili o collegabili in serie con facilità. Lo sketch gira sul Nano ma dovrebbe andare bene su tutti gli Arduini, semmai controllare la corrispondenza dei segnali sui piedini. Le librerie potete trovarle utilizzando la ricerca automatica della IDE oppure su GitHub.


Test of control of an economic array of LCD 8x8 matrix with reading a RTC module. The LCD matrix modules that I took are already grouped in 4 and can be connected to other modules in cascade, both horizontally and vertically. The library used uses the SPI connection (Serial Peripheral Interface) for module management and the RTC module uses I2C. In the Internet there are more easily individual 8x8 modules but these already assembled to 4 are also really comfortable because they are separable or connected in series with ease. The sketch runs on Nano but should be fine on all Arduini, if anything, check the correspondence of the signals on the pins. Libraries you can find them using automatic search of the IDE or on GitHub.




Dettaglio della connessione tra i singoli moduli.
The detail of the connection between the individual modules.


Il modulo acceso, molto luminoso.
The module turned on, very bright


// ***********************************
// Test Controllo LCD array con RTC
// Reteservizi di Paolo Fiaschi
// 2016
// ***********************************

#include 
#include 
#include 
#include 
#include "RTClib.h"

// ************************************
// connessione modulo LED<->Arduino
/*
VCC<->5V
GND<->GND
DIN<->D11
CS <->D10
CLK<->D13
*/

// connessione modulo RTC<->Arduino
/*
VCC<->5V
GND<->GND
SDA<->A4
SCL<->A5
*/

// ************************************
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 4; // numero display in orizzontale
int numberOfVerticalDisplays = 1;   // numero display in verticale

Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

RTC_DS1307 RTC;

String tape = "Scritta scorrevole...";
int wait = 30; // velocità di scorrimento in milliseconds

int spacer = 1;
int width = 5 + spacer; // 5 pixel di larghezza font

// senza spazi per presentarlo da solo
String mesi[] = {" gen "," feb "," mar "," apr "," mag "," giu "," lug "," ago "," set "," ott "," nov "," dic "};
// senza spazi per presentarlo attaccato alla data
String mesi1[] = {"gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic"}; 


// *******************************************
void setup() {

  Serial.begin(9600);

  // *** init RTC
  Wire.begin();
  RTC.begin();

  // **************
  // settaggio RTC
  // **************
  //If we remove the comment from the following line, we will set up the module time and date with the computer one
  //RTC.adjust(DateTime(__DATE__, __TIME__));

  matrix.setIntensity(7); // luminosità da 0 a 15

  // impostazione del n. del display utilizzato e delle sue caratteristiche di visualizzazione
  // vedi le specifiche della libreria Max72xxPanel

  // Imposta le proprieta di ogni display
  matrix.setPosition(0, 0, 0); // The first display is at <0, 0>
  //  matrix.setPosition(1, 1, 0); // The second display is at <1, 0>
  //  matrix.setPosition(2, 2, 0); // The third display is at <2, 0>
  //  matrix.setPosition(3, 3, 0); // And the last display is at <3, 0>
  //  ...
  matrix.setRotation(0, 1);    // Rovescia la visualizzazione del n display
  matrix.setRotation(1, 1);    // Rovescia la visualizzazione del n display
  matrix.setRotation(2, 1);    // Rovescia la visualizzazione del n display
  matrix.setRotation(3, 1);    // Rovescia la visualizzazione del n display

  // test:accende un pixel alla locazione 0,0 e uno alla 32,7
  /*
  matrix.fillScreen(LOW);
  matrix.drawPixel(0, 0, HIGH);
  matrix.drawPixel(32, 7, HIGH);  
  matrix.write();
  */

  // recupera la data
  DateTime now = RTC.now();
}

// *************************************
void loop() {

  // presenta la scritta scorrevole.
  StringScroll(tape);

  // recupera la data
  DateTime now = RTC.now();

  //mostra la l'ora
  //String ora=now.hour()+":"+now.minute();

  char buf[5];
  sprintf(buf, "%02d:%02d", now.hour(), now.minute());
  
  StringStatic(buf,2000);
  //StringStatic((String)now.hour()+":"+(String)now.minute(),2000);
  
  //mostra la la data
  //StringStatic((String)now.day()+" ",2000); // giorno da solo
  StringStatic((String)now.day()+mesi1[now.month()],2000);  // giorno insieme al mese
  StringStatic((String)now.year(),2000);
}

// ************************************
// visualizza la stringa scorrevole sul display
void StringScroll(String stringa) {
  for ( int i = 0 ; i < width * stringa.length() + matrix.width() - 1 - spacer; i++ ) {

    matrix.fillScreen(LOW);

    int letter = i / width;
    int x = (matrix.width() - 1) - i % width;
    int y = (matrix.height() - 8) / 2;

    while ( x + width - spacer >= 0 && letter >= 0 ) {
      if ( letter < stringa.length() ) {
        matrix.drawChar(x, y, stringa[letter], HIGH, LOW, 1);
      }

      letter--;
      x -= width;
    }

    matrix.write(); // Send bitmap to display

    delay(wait);
  }
}

// ************************************
// visualizza la stringa statica sul display per il tempo richiesto
void StringStatic(String stringa, int tempo) {

  matrix.fillScreen(LOW);
  
  for ( int i = 0 ; i < width * stringa.length() + matrix.width() - 1 - spacer; i++ ) {
    int letter = i / width;
    int x = (matrix.width() - 1) - i % width;
    int y = (matrix.height() - 8) / 2;

    while ( x + width - spacer >= 0 && letter >= 0 ) {
      if ( letter < stringa.length() ) {
        matrix.drawChar(x, y, stringa[letter], HIGH, LOW, 1);
      }

      letter--;
      x -= width;

      if (letter==stringa.length()-1) break;
    }
  }
  matrix.write(); // Send bitmap to display
  delay(tempo);
}

// *********************************
// ricompone i dati dell'RTC in un unico buffer
String ConvData(DateTime Data) {
  char buf[30];
  sprintf(buf, "%02d/%02d/%04d %02d:%02d:%02d", Data.day(), Data.month(), Data.year(), Data.hour(), Data.minute(), Data.second());

  return buf;
}


Nessun commento:

Posta un commento

Ciao, lascia un tuo commento o suggerimento relativo a quello che hai trovato su questo blog.