Δευτέρα 12 Μαΐου 2014

ATtiny85 and DS18B20 temperature sensors

Blue Backlight Nokia 5110 LCD Module  $ 3.75

Except to light up led the ATtiny85 can be useful and in other simple projects. The most annoying think is the memory limitation (only 8kb available). I plan to read multiple DS18B20 onewire sensors (I have two loose and one more soldered in an RTC module). The measured values will showed on an cheap Nokia 5110 screen. I can't manage to use the DallasTemperature Library because the above mentioned memory limitation. I use the standard OneWire.h library. I found also a TinyWire(M/S) library specially made for ATtiny but is for I2C communication (maybe in future update). For the 5110 LCD screen I use the basic library LCD5110_Basic from henningkarlsen.com

In order to use multiple sensors we need first to know the HEX address of each one. I use the "Arduino 1-Wire Address Finder" sketch (found in many sites) with my UNO and connect one by one sensor write down the address of each sensor and remember to mark also the sensor itself to identify letter on.  


To save one pin the CS pin of LCD is connected to the GND and the pin D4 is used as OneWire bus. After all connections the only free pin is the RESET pin. This pin can be used as D5 but with limit load. 




// ATtiny85 + Nokia 5110 LCD + 3x DS18B20 sensors
// Binary sketch size: 7,476 bytes (of a 8,192 byte maximum)
// wire connections
// 1-Wire bus > D4

// LCD Clk   >  D0         LCD Din   > D1
// LCD DC    >  D2         LCD CE    > GND
// LCD RST   >  D3

#include <OneWire.h>
#include <LCD5110_Basic.h>

LCD5110 myGLCD(0,1,2,3,6); //D6 don't exist!!! conected to GND!


extern uint8_t MediumNumbers[]; //font that we use

OneWire  ds(4);  // 1-wire bus D4

byte addr1[8]={0x28, 0xEC, 0xAF, 0x5B, 0x05, 0x00, 0x00, 0x6F}; //loose sensor #1
byte addr2[8]={0x28, 0x6D, 0xF0, 0x3B, 0x05, 0x00, 0x00, 0xD8}; //loose sensor #2
byte addr3[8]={0x28, 0x27, 0xA0, 0x5B, 0x05, 0x00, 0x00, 0x67}; //sensor soldered to RTC (#3)

float temp;

void setup(void) {
   myGLCD.InitLCD(); // (xx)contrast value 70 default
}

void loop(void) {
  myGLCD.setFont(MediumNumbers);
  byte i;
  byte present = 0;
  byte data[12];
 
 myGLCD.print("1.", LEFT, 0);
 myGLCD.print("2.", LEFT, 16);
 myGLCD.print("3.",LEFT, 32);

  ds.reset();
  ds.select(addr1);
// sensor #1
  ds.write(0x44,0); //start conversion, NO parasite power
  delay(750);
  present = ds.reset();
  ds.select(addr1);   
  ds.write(0xBE);         // Read Scratchpad
  for ( i = 0; i < 9; i++){

       data[i] = ds.read();
  }
  // convert the data to actual temperature
 temp = ( (data[1] << 8) + data[0] )*0.0625;
 myGLCD.printNumF(temp, 2, RIGHT, 0);
 

// I know doing three time the same is NOT a clever thing!!
// sketch need to optimize

 ds.reset();
  ds.select(addr2); // sensor #2
  ds.write(0x44,0); 

  delay(750);    
  present = ds.reset();
  ds.select(addr2);   
  ds.write(0xBE);        
  for ( i = 0; i < 9; i++)
  {          
    data[i] = ds.read();
  }
  temp = ( (data[1] << 8) + data[0] )*0.0625;
  myGLCD.printNumF(temp, 2, RIGHT, 16);

 ds.reset();
  ds.select(addr3);
// sensor #3
  ds.write(0x44);
  delay(750);    
  present = ds.reset();
  ds.select(addr3);   
  ds.write(0xBE);        
  for ( i = 0; i < 9; i++)
  {           // we need 9 bytes
    data[i] = ds.read();
  }
  temp = ( (data[1] << 8) + data[0] )*0.0625;
  myGLCD.printNumF(temp, 2, RIGHT, 32); 
}


Because my LCD 5110 board is capable to work with 3.3V AND 5V I don't use any additional resistors but the most of 5110 screens on ebay is only 3.3V so either use only 3.3V for all or use limiting resistors to the LCD. Both the microcontroller and the DS18B20 sensors working with 3.3/5 Volts without problems. 


4 σχόλια:

  1. hello, if we replace the ATtiny85 for attiny84, which pin should we use?

    ΑπάντησηΔιαγραφή
    Απαντήσεις
    1. I don't have any ATtiny85 but based to pinout diagram these is the equivalent connections
      D4=pin9 (1wire bus), D0=pin13, D1=pin12, D2=pin11, D3=pin10

      Διαγραφή
  2. Hello! I was wondering whats the meaning of the numbers 0,16 and 32, and what should I do with those numbers in the code if I wanted to add more sensors, thank you!

    ΑπάντησηΔιαγραφή
    Απαντήσεις
    1. These numbers is because the lcd library that I use, (MediumNumbers, 12x16 pixels) if you want to use same library with more sensors you can use other font (SmallFont 6x8 pixels = 6 rows) or you can make scroll routine (show 3 sensors for about 2-3 sec).

      Διαγραφή