ArduShop.ro

ArduShop.ro
cod Z4A413ZN reducere 5%, pentru vizitatorii paginilor mele !

luni, 17 iunie 2013

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

   Dupa ce am facut o prezentare a modului de conectare a afisajului folosit la vechile telefoane Nokia 5110 (5120, 5130, 5160, 6110, 6150, 3210, 3310, 3315, 3330, 3350, 3410, 6210) in prima parte, acum o sa continui cu partea concreta interconectare si de afisare.
   Dupa testarea mai multor librarii, m-am oprit la cea de la https://code.google.com/p/pcd8544/.
   Schema de conectare este:
   Spre surprinderea mea, chiar daca ordinea pinilor e diferita fata de modulele "consacrate", modul de conectare e simplu:
   Adaptand sketch-ul "Hello World!!" din exemplu, am obtinut o susccesiune de texte, ecranul devenind un afisaj de 14 coloane cu 5 randuri:
 
/*
 * PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
 *
 * Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/*
 * To use this sketch, connect the eight pins from your LCD like thus:
 *
 * Pin 1 -> +3.3V (rightmost, when facing the display head-on)
 * Pin 2 -> Arduino digital pin 3
 * Pin 3 -> Arduino digital pin 4
 * Pin 4 -> Arduino digital pin 5
 * Pin 5 -> Arduino digital pin 7
 * Pin 6 -> Ground
 * Pin 7 -> 10uF capacitor -> Ground
 * Pin 8 -> Arduino digital pin 6
 *
 * Since these LCDs are +3.3V devices, you have to add extra components to
 * connect it to the digital pins of the Arduino (not necessary if you are
 * using a 3.3V variant of the Arduino, such as Sparkfun's Arduino Pro).
 */

/* niq_ro ( http://nicuflorica.blogspot.ro ) case:
 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 
*/


#include <PCD8544.h>


// A custom glyph (a smiley)...
static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };


static PCD8544 lcd;


void setup() {
  // PCD8544-compatible displays may have a different resolution...
  lcd.begin(84, 48);
  
  // Add the smiley to position "0" of the ASCII table...
  lcd.createChar(0, glyph);
}


void loop() {
  // Just to show the program is alive...
  static int counter = 0;

  // Write a piece of text on the first line...
  lcd.setCursor(0, 0);
  lcd.print("Hi, all!");

  // Write a piece of text on the first line...
  lcd.setCursor(0, 2);
  lcd.print("niq_ro made");

  // Write a piece of text on the second line...
  lcd.setCursor(0, 3);
  lcd.print("tehnic.go.ro  ");
   lcd.setCursor(0, 4);
  lcd.print("              ");

  // Write the counter on the fifth line...
  lcd.setCursor(0, 5);
  lcd.print(counter, DEC);
  lcd.write(' ');
  lcd.write(0);  // write the smiley
  delay(2000);  

  // Write a piece of text on thirdh and fourth line...
  lcd.setCursor(0, 3);
  lcd.print("niqro.3x.ro    ");
  lcd.setCursor(0, 4);
  lcd.print("              ");
  delay(2000);  

  // Write a piece of text on thirdh and fourth line...
  lcd.setCursor(0, 3);
  lcd.print("nicuflorica.   ");
  lcd.setCursor(17, 4);
  lcd.print("blogspot.ro");
  delay(2000); 


  counter++;
}

   Am facut si un filmulet, numit Nokia 5110 LCD (PCD8544) and Arduino:

   Avand modulul de timp real cu DS1307 si senzorul de umiditate si temperatura DHT11, pe cere le-am tot folosit, am realizat schema de interconecate:
  Am "mixat" niste sketch-uri, rezultandu-mi:
 
// 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.0


#include <PCD8544.h> // library for Nokia 5110 LCD (PCD8544)
static PCD8544 lcd;

#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;

void setup () {
  // PCD8544-compatible displays may have a different resolution...
  lcd.begin(84, 48);
  // sensor DHT for humidity and temperature 
  dht.begin();

  // Print a logo message to the LCD.
  lcd.setCursor(0, 0);
  lcd.print("tehnic.go.ro");  
  lcd.setCursor(24, 1);
  lcd.print("& niq_ro");
  lcd.setCursor(1, 3);
  lcd.print("ceas-calendar");  
  lcd.setCursor(0, 4);
  lcd.print("temp. & umidit");
  lcd.setCursor(0, 5);
  lcd.print("versiunea 1.0");
  delay (5000);
  lcd.clear();  
  
  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__));
  }
}

void loop () {
  DateTime now = RTC.now();
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  
// lcd.clear();  
   lcd.setCursor(0, 0);
   if ( now.hour() < 10)
   {
     lcd.print(" "); 
     lcd.print(now.hour(), DEC);
   }
   else
   {
     lcd.setCursor(0, 0);
     lcd.print(now.hour(), DEC);
   }
   lcd.print(":");
   if ( now.minute() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.minute(), DEC);
   }
   else
   {
   lcd.print(now.minute(), DEC);
   }
   lcd.print(":");
   if ( now.second() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.second(), DEC);
   }
   else
   {
   lcd.print(now.second(), DEC);
   }
   lcd.print(" "); 
   
    
   lcd.setCursor(0, 1);
   if ( now.day() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.day(), DEC);
   }
   else
   {
   lcd.print(now.day(), DEC);
   }
   lcd.print("/");
   if ( now.month() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.month(), DEC);
   }
   else
   {
   lcd.print(now.month(), DEC);
   }
   lcd.print("/");
   lcd.print(now.year(), DEC);
   lcd.print(""); 
   
   lcd.setCursor(0, 4);
   lcd.print("temperat.=");
   lcd.print(t);
   lcd.print("^C");
     
   lcd.setCursor(0, 5);
   lcd.print("umiditate=");
   lcd.print(h);
   lcd.print("%");
  
   delay(500);
}

   Am pus si simbolul de grad Celsius:
// 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.1


#include <PCD8544.h> // library for Nokia 5110 LCD (PCD8544)
// A custom "degrees" symbol...
static const byte DEGREES_CHAR = 1;
static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };

static PCD8544 lcd;


#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;

void setup () {
  // PCD8544-compatible displays may have a different resolution...
  lcd.begin(84, 48);
   // Register the custom symbol...
  lcd.createChar(DEGREES_CHAR, degrees_glyph);
    
  // sensor DHT for humidity and temperature 
  dht.begin();

  // Print a logo message to the LCD.
  lcd.setCursor(0, 0);
  lcd.print("tehnic.go.ro");  
  lcd.setCursor(24, 1);
  lcd.print("& niq_ro");
  lcd.setCursor(1, 3);
  lcd.print("ceas-calendar");  
  lcd.setCursor(0, 4);
  lcd.print("temp. & umidit");
  lcd.setCursor(0, 5);
  lcd.print("versiunea 1.1");
  delay (5000);
  lcd.clear();  
  
  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__));
  }
}

void loop () {
  DateTime now = RTC.now();
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  
// lcd.clear();  
   lcd.setCursor(0, 0);
   if ( now.hour() < 10)
   {
     lcd.print(" "); 
     lcd.print(now.hour(), DEC);
   }
   else
   {
     lcd.setCursor(0, 0);
     lcd.print(now.hour(), DEC);
   }
   lcd.print(":");
   if ( now.minute() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.minute(), DEC);
   }
   else
   {
   lcd.print(now.minute(), DEC);
   }
   lcd.print(":");
   if ( now.second() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.second(), DEC);
   }
   else
   {
   lcd.print(now.second(), DEC);
   }
   lcd.print(" "); 
   
    
   lcd.setCursor(0, 1);
   if ( now.day() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.day(), DEC);
   }
   else
   {
   lcd.print(now.day(), DEC);
   }
   lcd.print("/");
   if ( now.month() < 10)
   {
     lcd.print("0"); 
     lcd.print(now.month(), DEC);
   }
   else
   {
   lcd.print(now.month(), DEC);
   }
   lcd.print("/");
   lcd.print(now.year(), DEC);
   lcd.print(""); 
   
   
   lcd.setCursor(0, 4);
   lcd.print("temperat.=");
   lcd.print(t);
   // lcd.print("^C");
   // lcd.setCursor(0, 3);
   lcd.print("\001C ");
   
   lcd.setCursor(0, 5);
   lcd.print("umiditate=");
   lcd.print(h);
   lcd.print("%");
  
   delay(500);
}
   Folosind informatiilede din articolul PCD8544 Glyph Editor am(re)creat "picatura"
si acum pe ecran am urmatoarele informatii:

    Deoarece caracterele obisnuite din mesajese pot citi doar de la distanta mare, am cautat si am constatat ca cei de la Adafruit au o librarie grafica, printre altele putand scrie cu caractere de dimensiuni mari.
 
   Acest mesaj a fost obtinut dupa ce am "curatat" sketch-ul din exemplele librarei, numit pcdtest.
/*********************************************************************
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);

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

}

void loop() {
}

   Am adaptat sketch-ul anterior la cel cu totate datele obtinand:
/*********************************************************************
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.3

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

// A custom "degrees" symbol...
// static const byte DEGREES_CHAR = 1;
// static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };

// A custom "drop" symbol...
// static const byte DROP_CHAR = 2;
// static const byte drop_glyph[] = { 0x70, 0x8c, 0x83, 0x8c, 0x70 };

#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;

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();
   // Register the custom symbol...
//  display.createChar(DEGREES_CHAR, degrees_glyph);
// display.createChar(DROP_CHAR, drop_glyph);
    
  // 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.3");
  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__));
  }
}

void loop () {
  DateTime now = RTC.now();
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  
// lcd.clear();
   display.setTextSize(1);
   display.setTextColor(BLACK);
   display.setCursor(0, 0);
   if ( now.hour() < 10)
   {
     display.print(" "); 
     display.print(now.hour(), DEC);
   }
   else
   {
     display.setCursor(0, 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.print(" "); 
   
    
   display.setCursor(0, 16);
   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);
   display.print(""); 
   
   display.setTextSize(3);
   display.setTextColor(BLACK);
   display.setCursor(0,25);
   display.print(t);
   display.print(" C");
   display.setTextSize(2);
   display.setTextColor(BLACK);
   display.setCursor(40,25);
   display.print("o");
   display.display();
   
   display.setTextSize(2);
   
   // display.setTextColor(WHITE, BLACK);
   display.setCursor(48,0);
   display.print(h);
   display.print("%"); 
   display.display();

   delay(500);
   display.clearDisplay();  

}

   Am modificat programiorul (sketch-ul) sa imi afiseze temperatura cu caractere si mai mari, apoi umiditatea.. timpul de afisare al temepraturii este mai mare decat al umiditatii de cca. 3 ori...
 
19.iun.2013
   Am recreat "picatura":
si am modificat timpii de afisare ai temperaturii si umiditatii, cate 5 secunde fiecare, dupa cum se vede in filmuletul demonstrativ date and hour, temperature and humidity with RTC DS1307 DHT11 Nokia LCD PCD8544 with Arduino (III)
Sketch-ul 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
// 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.6

#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.6");
  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();

   display.setTextSize(1);
   display.setTextColor(BLACK);
   display.setCursor(20, 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.print(" "); 
   
//   int k0 = now.second(); 
//   int k1 = k0/3;
   int zs = now.second()/10;
   int us = now.second() - zs*10;
   
   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();  
}

5 comentarii:

  1. cv pentru ESP8266 nu aveti materiale...ca am cautat dar nimic ..il alimentez il vede leptopyl telefonul ca retea wireles etc. dar as vrea sa il fac sa lucreze ca bluetooth.sa trimiti din leptop din serial monitor info sa le primesc pe telefon si invers.sau de la un leptop la altul ...in momentul cand ma conectez la modul sa comunice tx rx ...
    va multumesc is de mare folos tutorialele dumneavoastra cred ca santeti singurul roman care face asa cv sa ajute in domeniul asta al arduino

    RăspundețiȘtergere
    Răspunsuri
    1. cum sa am aici, daca titlul e "Afisajul folosit la telefoanele Nokia 5110/3310 si Arduino (II)" ?
      in partea de sus, in stanga, e o casuta de cautare...scrieti ESP8266 siu apasati pe lupa.. va duce la http://nicuflorica.blogspot.ro/2015/03/modulul-de-retea-uairles-esp8266-05-si.html
      revenind la chestii tehnice ESP8266 este pentru comunicatia "wi-fi" nu bluetooth... si, pentru ultima parte, eu sunt mai "prost' si arat si celorlalti...

      Ștergere
  2. static unsigned char PROGMEM const picatura[] =

    RăspundețiȘtergere
    Răspunsuri
    1. if use Arduino IDE 1.6.x try older version, like 1.0.y... if use older version, try new...

      Ștergere