joi, 20 iunie 2013

Afisajul folosit la telefoanele Nokia 5110/3310 si Arduino (III)

   Fata de partea a II-a, unde ultima indicatie era de genul:
adica: ora si data scrise cu caractere normale, afisate permanent, iar temperatura si umiditatea cu caractere triple, afisate cu intermitenta cand una cand alta, la interval de 5 secunde), acum am modificat sketch-ul pentru a avea urmatoarele situatii:
- timp de 3 secunde ( cand unitatile de secunde sunt 0, 1 si 2) se afiseaza ra si data scrise cu caractere normale, iar temperatura cu caractere triple:
- timp de 3 secunde (cand unitatile de secunde sunt 3, 4 si 5) se afiseaza ora cu caractere duble, temperatura ramanand ca si inainte:
- timp de 5 secunde (cand unitatile de secunde sunt 6, 7,8 si 9) se afiseaza in continuare ora cu caractere duble, iar umiditatea se afiseaza cu caractere triple:
dupa care se reia intreg ciclul, acesta putand fi inteles mai bine daca vizionati filmuletul date and hour, temperature and humidity with RTC DS1307 DHT11 Nokia LCD PCD8544 with Arduino (IV)
sau in cel cu o calitatea mai buna, numit date and hour, temperature and humidity with RTC DS1307 DHT11 Nokia LCD PCD8544 with Arduino (V)
Sketch-ul folosit este:
/*********************************************************************
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
*********************************************************************/

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
// Nokia 5110 LCD (PCD8544) from https://code.google.com/p/pcd8544/
// adapted sketch for DHT11 by by niq_ro from http://nicuflorica.blogspot.ro

/* niq_ro ( http://nicuflorica.blogspot.ro ) case for Nokia 5110 LCD (PCD8544) - LPH 7366:
 For module from China, you must connect like this:
* Pin 1 (RST) -> Arduino digital 6 (D6)
* Pin 2 (CE) -> Arduino digital 7 (D7)
* Pin 3 (DC) -> Arduino digital 5 (D5)
* Pin 4 (DIN) -> Arduino digital 4 (D4)
* Pin 5 (CLK) - Arduino digital 3 (D3)
* Pin 6 (Vcc) -> +5V thru adaptor module (see http://nicuflorica.blogspot.ro/2013/06/afisajul-folosit-la-telefoanele-nokia.html )
* Pin 7 (LIGHT) -> +5V thru 56-100 ohms resistor (for permanent lights) or... other pin control
* Pin 8 (GND) -> GND1 or GND2 
*/

// version 1.7

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// Adafruit_PCD8544 display = Adafruit_PCD8544(SCLK, DIN, DC, CS, RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);

#include <DHT.h>
#define DHTPIN A2     // what pin we're connected DHT11
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);


#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

static unsigned char PROGMEM picatura[] =
{ B0001000,
  B0001000,
  B0001000,
  B0010100,
  B0100010,
  B0100010,
  B0011100
};

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();

  // sensor DHT for humidity and temperature 
  dht.begin();

  // Print a logo message to the LCD.
  
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("tehnic.go.ro");
  display.setCursor(24, 8);
  display.print("& niq_ro");
  display.setCursor(1, 24);
  display.print("ceas-calendar");  
  display.setCursor(0, 32);
  display.print("temp. & umidit");
  display.setCursor(0, 40);
  display.print("versiunea ");
  display.setTextColor(WHITE, BLACK);
  display.print("1.7");
  display.display();
  delay (5000);
  display.clearDisplay(); 
  
  Wire.begin();
  
// part code from http://tronixstuff.wordpress.com/
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
// end part code from http://tronixstuff.wordpress.com/

    RTC.begin();
// RTC.adjust(DateTime(__DATE__, __TIME__));
// if you need set clock... just remove // from line above this
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

int k1;
int ko;

void loop () {
  
  DateTime now = RTC.now();
  int h = dht.readHumidity();
  int t = dht.readTemperature();

   // need for display time 
   int zs = now.second()/10;
   int us = now.second() - zs*10;
  
  if (us > 2 )
 {
   display.setTextSize(2);
   display.setTextColor(BLACK);
   display.setCursor(0, 0);
   
   
   {   if ( now.hour() < 10)
   {
     display.print(" "); 
     display.print(now.hour(), DEC);
   }
   else
   {
     display.print(now.hour(), DEC);
   }
   display.setCursor(20, 0);
   display.print(":");
   display.setCursor(28, 0);
   if ( now.minute() < 10)
   {
     display.print("0"); 
     display.print(now.minute(), DEC);
   }
   else
   {
   display.print(now.minute(), DEC);
   }

   display.setCursor(48, 0);
   display.print(":");
   display.setCursor(57, 0);
   if ( now.second() < 10)
   {
     display.print("0"); 
     display.print(now.second(), DEC);
   }
   else
   {
   display.print(now.second(), DEC);
   }
   }
 }
 else 
 {
   display.setTextSize(1);
   display.setTextColor(BLACK);
   display.setCursor(16, 0);
   if ( now.hour() < 10)
   {
     display.print(" "); 
     display.print(now.hour(), DEC);
   }
   else
   {
   //  display.setCursor(16, 0);
     display.print(now.hour(), DEC);
   }
   display.print(":");
   if ( now.minute() < 10)
   {
     display.print("0"); 
     display.print(now.minute(), DEC);
   }
   else
   {
   display.print(now.minute(), DEC);
   }
   display.print(":");
   if ( now.second() < 10)
   {
     display.print("0"); 
     display.print(now.second(), DEC);
   }
   else
   {
   display.print(now.second(), DEC);
   }
      
   display.setCursor(10, 8);
   if ( now.day() < 10)
   {
     display.print("0"); 
     display.print(now.day(), DEC);
   }
   else
   {
   display.print(now.day(), DEC);
   }
   display.print("/");
   if ( now.month() < 10)
   {
     display.print("0"); 
     display.print(now.month(), DEC);
   }
   else
   {
   display.print(now.month(), DEC);
   }
   display.print("/");
   display.print(now.year(), DEC);
 }
     
    if (us < 5 )
   {
   display.setTextSize(4);
   display.setTextColor(BLACK);
   display.setCursor(0,20);
   display.print(t);
   display.setCursor(60,20);
   display.print("C");
   display.setTextSize(2);
   display.setTextColor(BLACK);
   display.setCursor(48,20);
   display.print("o");
   display.display();
   }
else
   {
   display.setTextSize(4);
// display.setTextColor(WHITE, BLACK);
   display.setCursor(0,20);
   display.print(h);
   display.setCursor(60,20);
   display.print("H");
   display.drawBitmap(50, 36,  picatura, 8, 8, 1);
   display.drawBitmap(44, 40,  picatura, 8, 8, 1);
  
   display.setTextSize(2);
   display.setTextColor(BLACK);
   display.setCursor(48,20);
   display.print("%");
   display.display();
   }

delay (500);
display.clearDisplay();  
}

   Schema de conectare a modulelor este aceeasi ca cea din partea a II-a.
   La recomandarea lui Andrei, am "pictat" un pahar, al carui nivel de lichid variaza cu procentul umiditatii:
 
/*********************************************************************
This is an example sketch for our Monochrome Nokia 5110 LCD Displays
  Pick one up today in the adafruit shop!
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
*********************************************************************/

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// Nokia 5110 LCD (PCD8544) from https://code.google.com/p/pcd8544/
// adapted sketch for DHT11 by by niq_ro from http://nicuflorica.blogspot.ro

/* niq_ro ( http://nicuflorica.blogspot.ro ) case for Nokia 5110 LCD (PCD8544) - LPH 7366:
 For module from China, you must connect like this:
* Pin 1 (RST) -> Arduino digital 6 (D6)
* Pin 2 (CE) -> Arduino digital 7 (D7)
* Pin 3 (DC) -> Arduino digital 5 (D5)
* Pin 4 (DIN) -> Arduino digital 4 (D4)
* Pin 5 (CLK) - Arduino digital 3 (D3)
* Pin 7 (LIGHT) -> +5V thru 56-100 ohms resistor (for permanent lights) or... other pin control
* Pin 8 (GND) -> GND1 or GND2 
*/

// version 1.8

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// Adafruit_PCD8544 display = Adafruit_PCD8544(SCLK, DIN, DC, CS, RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);

#include <DHT.h>
#define DHTPIN A2     // what pin we're connected DHT11
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);


#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

static unsigned char PROGMEM picatura[] =
{ B0001000,
  B0001000,
  B0001000,
  B0010100,
  B0100010,
  B0100010,
  B0011100
};

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();

  // sensor DHT for humidity and temperature 
  dht.begin();

  // Print a logo message to the LCD.
  
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("tehnic.go.ro");
  display.setCursor(24, 8);
  display.print("& niq_ro");
  display.setCursor(1, 24);
  display.print("ceas-calendar");  
  display.setCursor(0, 32);
  display.print("temp. & umidit");
  display.setCursor(0, 40);
  display.print("versiunea ");
  display.setTextColor(WHITE, BLACK);
  display.print("1.8");
  display.display();
  delay (5000);
  display.clearDisplay(); 
  
  Wire.begin();
  
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
// end part code from http://tronixstuff.wordpress.com/

    RTC.begin();
// RTC.adjust(DateTime(__DATE__, __TIME__));
// if you need set clock... just remove // from line above this
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

int k1;
int ko;

void loop () {
  
  DateTime now = RTC.now();
  int h = dht.readHumidity();
  int t = dht.readTemperature();

   // need for display time 
   int zs = now.second()/10;
   int us = now.second() - zs*10;
  
  if (us > 2 )
 {
   display.setTextSize(2);
   display.setTextColor(BLACK);
   display.setCursor(0, 0);
   
   
   {   if ( now.hour() < 10)
   {
     display.print(" "); 
     display.print(now.hour(), DEC);
   }
   else
   {
     display.print(now.hour(), DEC);
   }
   display.setCursor(20, 0);
   display.print(":");
   display.setCursor(28, 0);
   if ( now.minute() < 10)
   {
     display.print("0"); 
     display.print(now.minute(), DEC);
   }
   else
   {
   display.print(now.minute(), DEC);
   }

   display.setCursor(48, 0);
   display.print(":");
   display.setCursor(57, 0);
   if ( now.second() < 10)
   {
     display.print("0"); 
     display.print(now.second(), DEC);
   }
   else
   {
   display.print(now.second(), DEC);
   }
   }
 }
 else 
 {
   display.setTextSize(1);
   display.setTextColor(BLACK);
   display.setCursor(16, 0);
   if ( now.hour() < 10)
   {
     display.print(" "); 
     display.print(now.hour(), DEC);
   }
   else
   {
   //  display.setCursor(16, 0);
     display.print(now.hour(), DEC);
   }
   display.print(":");
   if ( now.minute() < 10)
   {
     display.print("0"); 
     display.print(now.minute(), DEC);
   }
   else
   {
   display.print(now.minute(), DEC);
   }
   display.print(":");
   if ( now.second() < 10)
   {
     display.print("0"); 
     display.print(now.second(), DEC);
   }
   else
   {
   display.print(now.second(), DEC);
   }
      
   display.setCursor(10, 8);
   if ( now.day() < 10)
   {
     display.print("0"); 
     display.print(now.day(), DEC);
   }
   else
   {
   display.print(now.day(), DEC);
   }
   display.print("/");
   if ( now.month() < 10)
   {
     display.print("0"); 
     display.print(now.month(), DEC);
   }
   else
   {
   display.print(now.month(), DEC);
   }
   display.print("/");
   display.print(now.year(), DEC);
 }
     
    if (us < 5 )
   {
   display.setTextSize(4);
   display.setTextColor(BLACK);
   display.setCursor(0,20);
   display.print(t);
   display.setCursor(60,20);
   display.print("C");
   display.setTextSize(2);
   display.setTextColor(BLACK);
   display.setCursor(48,20);
   display.print("o");
   display.display();
   }
else
   {
   display.setTextSize(4);
// display.setTextColor(WHITE, BLACK);
   display.setCursor(0,20);
   display.print(h);
/*   display.setCursor(60,20);
   display.print("H");
*/
   // draw an empty glass
   display.drawLine(60, 20, 60, 45, BLACK);
   display.drawLine(61, 20, 61, 45, BLACK);
   display.drawLine(60, 44, 80, 44, BLACK);
   display.drawLine(60, 45, 80, 45, BLACK);
   display.drawLine(79, 20, 79, 45, BLACK);
   display.drawLine(80, 20, 80, 45, BLACK);
// display.display();
   int hp = h/4;
   for (int x = 0; x < hp+1; x++)
   { 
   display.drawLine(60, 44-x, 80, 44-x, BLACK);
   }
 // draw drops water
   display.drawBitmap(65, 20,  picatura, 8, 8, 1);
   display.drawBitmap(70, 26,  picatura, 8, 8, 1);
  
   display.setTextSize(2);
   display.setTextColor(BLACK);
   display.setCursor(48,20);
   display.print("%");
   display.display();
   }

delay (500);
display.clearDisplay();  
}


16 comentarii:

  1. Nicu, cum ai facut imaginile ? Ca mie nu-mi iese nici cum...

    RăspundețiȘtergere
    Răspunsuri
    1. folosesti libraria grafica de la Adafruit (GFX) si incarci sketch-urile mele....

      Ștergere
  2. astea mi-au mers, dar cum ai transformat bmp-ul la pixeli ?

    RăspundețiȘtergere
    Răspunsuri
    1. nu am transformat nici o poza in pixeli..daca la asta te referi.. picatura am facut-o din conversia unei picaturi desenate intr-un caracter de 6x8 daca retin bine pe o foaie de hartie.. dar am scris cum am facut in articolele anterioaare, de asta asta titlul are un III in paranteze... oricum daca nu e foarte clar la mine exista cautare pe net....

      Ștergere
  3. Please can you help me?
    I need your dht library because program give me error to a line: DHT dht(DHTPIN, DHTTYPE)
    Thanks!
    Antonio

    RăspundețiȘtergere
  4. nice tutorial and code, can you for me code?

    RăspundețiȘtergere
    Răspunsuri
    1. in this article I put all code/sketch for all examples...for more details (for schematic) look at http://nicuflorica.blogspot.ro/2013/06/afisajul-folosit-la-telefoanele-nokia_17.html and http://nicuflorica.blogspot.ro/2013/06/afisajul-folosit-la-telefoanele-nokia.html

      Ștergere
  5. Hi Nicu.
    I noticed that the DS1307 is not very accurate. It is possible to change the time without using a computer? (Maybe adding a few buttons to change the time). Can you tell me how to change the code?
    Thank you!
    Antonio.

    RăspundețiȘtergere
  6. Hi Antoniu,
    My DS1307 is very accurate, but I put 3 buttons for change the time, see http://nicuflorica.blogspot.ro/2013/12/afisaje-led-cu-7-segmente-si-arduino-iv.html (is for 7-segment LED, but is same..)

    RăspundețiȘtergere
  7. Hi Nicu, many thanks for your reply.
    I have tried to insert the three buttons and the code for their operation but still there is something that does not work. Could you help me? How can I change the code? I'm sorry but I'm novice. Many thanks in advance!!
    Greetings.
    Antonio

    RăspundețiȘtergere
  8. you must give me your sketch at my mail: nicuflorica2gmail.com and I'll try to made ok

    RăspundețiȘtergere
  9. Nicu your blog and arduino circuits are great, this is my main reference for my arduino learning, many thanks

    RăspundețiȘtergere
  10. The blog is absolutely fantastic. Lots of great information and inspiration, both of which we all need.
    Ecommerce Web Designing Company Magento Web Development Company Joomla Web Design Company

    RăspundețiȘtergere
  11. Salut,

    Se poate conecta LCD 128x64 - ST7920 la Arduino uno, astfel incat sa poata fi folosite librariile Adafruit?
    Ceva ca si conexiunea din:
    http://nicuflorica.blogspot.ro/search?q=128x64

    Multumesc.

    RăspundețiȘtergere
  12. Hi

    I'm getting this error during compilation. Do you have any Idea whot is the reason?

    THX in advance for any solution.

    sketch_jan30g:50: error: variable 'picatura' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

    static unsigned char PROGMEM picatura[] =

    ^

    exit status 1
    variable 'picatura' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

    RăspundețiȘtergere
  13. строку static unsigned char PROGMEM picatura[] =
    надо записать так static unsigned char PROGMEM const picatura[] =

    RăspundețiȘtergere