Bonjour,
Toujours pour le fun, je suis tombé sur un montage du type "Speedométre GPS" avec un affichage en gros caractéres sur un LCD 12864 et utilisation de la bibliothèque "openGLCD".
L'ennui c'est que le concepteur utilise un montage avec un câblage complet du LCD soit 20 liaisons !!!
J'avais réalisé il y a quelques temps une platine permettant une liaison du type SPI avec seulement 5 fils sur ce LCD et bien décidé à utiliser cette facilité je me suis lancé à la recherche d'une bibliothèque ad hoc. La librairie u8g fonctionne très bien mais je n'ai pas trouvé comment modifier le sketch pour l'utiliser. J'en ai finalement trouvé une "LCD12468SPI" qui fonctionne.
/*
LCD Arduino
PIN1 = GND
PIN2 = 5V
RS(CS) = 8;
RW(SID)= 9;
EN(CLK) = 3;
PIN15 PSB = GND;
*/
#include "LCD12864RSPI.h"
void setup()
{
LCDA.initialise();
delay(100);
}
int i = 1;
void loop()
{
LCDA.clear();
delay(10);
LCDA.printf(0, 0, "This is an integer %d, which will be incremented.", i);
delay(1000);
i++;
}
Il existe manifestement au moins deux librairies avec des variables du genre "Initialise" ou "initialise" et elles ne se parlent pas !!!!
j'ai tenté de l'implanter sur le code du speedometre et tout avait l'air d'aller bien jusqu'à la ligne 73 où je n'ai pas trouvé comment remplacer:
"GLCD.DrawBitmap(Number0, pos, 0);" par son équivalent avec "LCD12468SPI"
#include <math.h> //math library to use for round function
#include "TinyGPS.h" //GPS module library
#include <openGLCD.h> // LCD library
TinyGPS gps; //create a gps object
float fLat, fLong; //floats for longitude and latitude; will be used to determine whether the GPS data is up to date or not
unsigned long fix_age; // returns +- latitude/longitude in degrees
int digit1, digit2, digit3; //integers to hold the three digits making up the speed
int iSpeed; //integer to hold the speed value from the GPS module
void setup()
{
Serial.begin(9600); //start the serial communication
// initialise the library, non inverted writes pixels onto a clear screen
GLCD.Init(NON_INVERTED);
}
void loop()
{
while (Serial.available())
{
//incoming serial data from GPS
int c = Serial.read();
if (gps.encode(c))
{
// process new gps info here, in case you want to display more details
}
}
gps.f_get_position(&fLat, &fLong, &fix_age); //get longitude and latitude, used to find if data is up to date
if (fix_age == TinyGPS::GPS_INVALID_AGE || fix_age > 2000)
{
//data was not updated for some time, assume that GPS connection is lost
iSpeed = 0;
}
else
{
//GPS connection is up to date, get the speed information, and round it to closest integer value
iSpeed = round(gps.f_speed_kmph()); // speed in km/h
}
//when not moving, the GPS module will still read some "speed" value, not necessarily zero
//in that case assume the car is not moving; only display values greater than 2
if (iSpeed == 1) iSpeed = 0;
displaySpeed(iSpeed); //call function to display the speed, digit by digit
}
void displaySpeed(int iSpeed)
{
//"simple" maths to extract each digit value
digit1 = iSpeed / 100;
iSpeed = iSpeed - (digit1 * 100);
digit2 = iSpeed / 10;
digit3 = iSpeed - (digit2 *10);
//display "blank" bitmap when necessary, instead of number zero
if (digit2 == 0 && digit1 == 0) digit2 = -1; //digit 2 is blank
if (digit1 == 0) digit1 = -1; //digit 1 is blank
//call function to display each digit, at their required position
drawDigit(digit1, 0);
drawDigit(digit2, 45);
drawDigit(digit3, 90);
}
void drawDigit(int digit, int pos)
{
switch (digit)
{
case 0:
GLCD.DrawBitmap(Number0, pos, 0);
break;
case 1:
GLCD.DrawBitmap(Number1, pos, 0);
break;
case 2:
GLCD.DrawBitmap(Number2, pos, 0);
break;
case 3:
GLCD.DrawBitmap(Number3, pos, 0);
break;
case 4:
GLCD.DrawBitmap(Number4, pos, 0);
break;
case 5:
GLCD.DrawBitmap(Number5, pos, 0);
break;
case 6:
GLCD.DrawBitmap(Number6, pos, 0);
break;
case 7:
GLCD.DrawBitmap(Number7, pos, 0);
break;
case 8:
GLCD.DrawBitmap(Number8, pos, 0);
break;
case 9:
GLCD.DrawBitmap(Number9, pos, 0);
break;
default:
GLCD.DrawBitmap(NumberBlank, pos, 0);
break;
}
}
Si quelqu'un a une idée j'en serais trés heureux bien sûr.
Merci.
