Schema de conectare, inclusiv adaptorul de tensiuni e acelasi:
M-am gandit la un secundar de ceas...
iar porecla de pe net (niq_ro) sa fie afisat in partea de jos cand secundarul este in zona de sus, respectiv in partea de sus cand secundarul este in partea de jos:
Pentru a desena ceva, trebuie sa stim ca dimensiunea utila este de 84 de puncte pe orizontala si 48 pe verticala, punctul notat cu (0,0) este in coltul din stanga sus, iar cel cu (83, 47) este in dreapta jos.
In libraria grafica Adafruit_GFX, comanda pentru linie, este:
display.drawLine(x0,y0, x1, y1, BLACK);
(x0,y0) sunt coordonatele punctului de inceput, iar (x1,y1) sunt coordonatele punctului de final al liniei.
Pentru a desena un cerc, comanda este urmatoarea:
display.drawCircle(x0, y0, r, BLACK);
(x0,y0) sunt coordonatele centrului cercului, iar r este raza cercului.Un prim filmulet, realizat cu un telefon Samsung, se numeste Adafruit GFX library + Nokia 5110 LCD + niq_ro's sketch (I):
Am folosit si un aparat foto FujiFilm S5700, filmuletul numindu-se Adafruit GFX library + Nokia 5110 LCD + niq_ro's sketch (III)
Sketch-ul scris de mine, care "face" ce se vede in cele 3 filmulete este urmatorul:
// original sketch by niq_ro, created in 7.aug.2013 at Santanandrei, Hunedoara
// using graphics library (GFX) from Adafruit
/*********************************************************************
This is an example sketch for our Monochrome Nokia 5110 LCD Displays
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/338
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include <Adafruit_GFX.h>
// using library for LCD Nokia 5110/3310 type
#include <Adafruit_PCD8544.h>
// for my Nokia 5110 LCD from China
// see http://nicuflorica.blogspot.ro/2013/06/afisajul-folosit-la-telefoanele-nokia.html
// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 7 - LCD chip select (CS)
// pin 6 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(SCLK, DIN, DC, CS, RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);
// center
int x0=84/2;
int y0=48/2;
// radius
int r=23;
// angle
int alfa=0;
void setup() {
Serial.begin(9600);
display.begin();
// init done
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(50);
display.clearDisplay();
// text display tests
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("tehnic. go.ro");
display.setTextSize(2);
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(" niq_ro ");
display.display();
delay(2000);
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(0,0);
display.println(" Adafruit GFX ");
display.setCursor(15,10);
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(" library ");
display.setCursor(0,20);
display.setTextColor(BLACK); // 'inverted' text
display.println("--------------");
display.setCursor(0,30);
display.setTextColor(BLACK); // 'normal' text
display.println("niq_ro's progr");
display.setCursor(5,40);
display.setTextColor(BLACK); // 'normal' text
display.println("version 1.0");
display.display();
delay(2000);
display.clearDisplay();
// center
display.drawCircle(x0, y0, 1, BLACK);
// master circle
display.drawCircle(x0, y0, r, BLACK);
// line 1
display.drawLine(x0,y0, x0+r, y0, BLACK);
display.display();
delay(500);
// line 2
display.drawLine(x0,y0, x0, y0+r, BLACK);
display.display();
delay(500);
// line 3
display.drawLine(x0,y0, x0-r, y0, BLACK);
display.display();
delay(500);
// line 4
display.drawLine(x0,y0, x0, y0-r, BLACK);
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
// display a moving line on circle
for (int alfa=0; alfa<60; alfa+=1)
{
display.drawLine(x0,y0, x0+r*sin(6*alfa*2*3.14/360), y0-r*cos(6*alfa*2*3.14/360), BLACK);
display.drawCircle(x0, y0, r, BLACK);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(alfa);
if (alfa <15 || alfa>45)
{display.setCursor(25,30);}
else
{display.setCursor(25,10);}
display.println("niq_ro");
display.display();
delay(1000);
display.clearDisplay();
}
}
Ulterior, am mai adaugat si un minutar care se misca, apoi o "limba" de orar, pentru a anima am scazut timpul dintre miscari cu 2,5%...
- secundar:
- minutar:
- orar:
Sketch-ul modificat este urmatorul:
// initial version is created by niq_ro at Santuhalm (Deva)
// current version (ver. 1.1) is modified by niq_ro at Craiova (26.8.2013)
/*********************************************************************
This is an example sketch for our Monochrome Nokia 5110 LCD Displays
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/338
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// for my Nokia 5110 LCD from China
// see http://nicuflorica.blogspot.ro/2013/06/afisajul-folosit-la-telefoanele-nokia.html
// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 7 - LCD chip select (CS)
// pin 6 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(SCLK, DIN, DC, CS, RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);
// center
int x0=84/2;
int y0=48/2;
// radius for circle
int r=23;
// angle
int alfa=0;
// lengh for minute hand (minutar)
int r1=20;
int r2=18;
// lengh for minute hand (orar)
int r3=15;
int r4=12;
// initial version is created by niq_ro at Santuhalm (Deva)
// current version (ver. 1.1) is modified by niq_ro at Craiova (26.8.2013)
void setup() {
Serial.begin(9600);
display.begin();
// init done
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(50);
display.clearDisplay();
// text display tests
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("tehnic. go.ro");
display.setTextSize(2);
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(" niq_ro ");
display.display();
delay(2000);
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(0,0);
display.println(" Adafruit GFX ");
display.setCursor(15,10);
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(" library ");
display.setCursor(0,20);
display.setTextColor(BLACK); // 'inverted' text
display.println("--------------");
display.setCursor(0,30);
display.setTextColor(BLACK); // 'normal' text
display.println("niq_ro's progr");
display.setCursor(5,40);
display.setTextColor(BLACK); // 'normal' text
display.println("version 1.1");
display.display();
delay(2000);
display.clearDisplay();
// center
display.drawCircle(x0, y0, 1, BLACK);
// master circle
display.drawCircle(x0, y0, r, BLACK);
// line 1
display.drawLine(x0,y0, x0+r, y0, BLACK);
display.display();
delay(500);
// line 2
display.drawLine(x0,y0, x0, y0+r, BLACK);
display.display();
delay(500);
// line 3
display.drawLine(x0,y0, x0-r, y0, BLACK);
display.display();
delay(500);
// line 4
display.drawLine(x0,y0, x0, y0-r, BLACK);
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
// display a moving line on circle (as second on analog clock)
int t1 = 1000; // time beetwin moving second
for (int alfa=0; alfa<60; alfa+=1)
{
// display circle
display.drawCircle(x0, y0, r, BLACK);
// display a moving line as second
float alfa1 = 3.14*alfa/30; // convert ungle from degree in radian
display.drawLine(x0,y0, x0+r*sin(alfa1), y0-r*cos(alfa1), BLACK);
// display a text with my nickmane (niq_ro)
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(alfa);
if (alfa <15 || alfa>45)
{display.setCursor(25,30);}
else
{display.setCursor(25,10);}
display.println("niq_ro");
display.display();
delay(t1);
t1 = t1 *0.975; // reduce the time between movements
display.clearDisplay();
}
// design a new clock just with a minute hand (minutar)
int t2 = 1000; // time beetwin moving minutar
for (int alfa=0; alfa<60; alfa+=1)
{
// display circle
display.drawCircle(x0, y0, r, BLACK);
// display a moving line as second
float alfa1 = 3.14*alfa/30; // convert ungle from degree in radian
float gama = 3.14/36; // value in radian for 5 degree
// display main line for minute hand
display.drawLine(x0,y0, x0+r1*sin(alfa1), y0-r1*cos(alfa1), BLACK);
// display outside line 1
display.drawLine(x0,y0, x0+r2*sin(alfa1-gama), y0-r2*cos(alfa1-gama), BLACK);
// display outside line 2
display.drawLine(x0,y0, x0+r2*sin(alfa1+gama), y0-r2*cos(alfa1+gama), BLACK);
// display outside line 3
display.drawLine(x0+r2*sin(alfa1+gama), y0-r2*cos(alfa1+gama), x0+r1*sin(alfa1), y0-r1*cos(alfa1), BLACK);
// display outside line 4
display.drawLine(x0+r2*sin(alfa1-gama), y0-r2*cos(alfa1-gama), x0+r1*sin(alfa1), y0-r1*cos(alfa1), BLACK);
// display a text with my nickmane (niq_ro)
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(alfa);
if (alfa <15 || alfa>45)
{display.setCursor(25,30);}
else
{display.setCursor(25,10);}
display.println("niq_ro");
display.display();
delay(t2);
t2 = t2 *0.975; // reduce the time between movements
display.clearDisplay();
}
// design a new clock just with a hour hand (orar)
int t3 = 1000; // time beetwin moving minutar
for (int alfa=0; alfa<60; alfa+=1)
{
// display circle
display.drawCircle(x0, y0, r, BLACK);
// display a moving line as second
float alfa1 = 3.14*alfa/30; // convert ungle from degree in radian
float gama = 3.14/36; // value in radian for 5 degree
// display main line for minute hand
display.drawLine(x0,y0, x0+r3*sin(alfa1), y0-r3*cos(alfa1), BLACK);
// display outside line 1
display.drawLine(x0,y0, x0+r4*sin(alfa1-gama), y0-r4*cos(alfa1-gama), BLACK);
// display outside line 2
display.drawLine(x0,y0, x0+r4*sin(alfa1+gama), y0-r4*cos(alfa1+gama), BLACK);
// display outside line 3
display.drawLine(x0+r4*sin(alfa1+gama), y0-r4*cos(alfa1+gama), x0+r3*sin(alfa1), y0-r3*cos(alfa1), BLACK);
// display outside line 4
display.drawLine(x0+r4*sin(alfa1-gama), y0-r4*cos(alfa1-gama), x0+r3*sin(alfa1), y0-r3*cos(alfa1), BLACK);
// display a text with my nickmane (niq_ro)
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(alfa);
if (alfa <15 || alfa>45)
{display.setCursor(25,30);}
else
{display.setCursor(25,10);}
display.println("niq_ro");
display.display();
delay(t3);
t3 = t3 *0.975; // reduce the time between movements
display.clearDisplay();
}
}
Filmuletul ce prezinta ce am scris mai sus se numeste Adafruit GFX library + Nokia 5110 LCD + niq_ro's sketch (IV)
Aceasta grafica se poate folosi sa se afiseze un ceas analog cu date citite de pe un ceas de timp real (RTC) cu DS1307, de exemplu...
15.01.2014
Deoarece intre timp afisajul a "decedat" din cauza contactului elastic prost intre cablaj si ecran, am achizitionat altul si l-am testat cu acest sketch, facand si filmuletul graphic test with my new Nokia 5110 LCD module
se poate folosi arduino nano fara a fi modificat nimic pentru testarea unor lcd de nokia 5110 cu LPH7366
RăspundețiȘtergereDAR lcd-ul este cu 9 pini
RăspundețiȘtergere