ArduShop.ro

ArduShop.ro
cod tehnic.go.ro_02 reducere 5%, pentru vizitatorii paginilor mele !

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