Nieuw in Arduino land en een eerste werkende projectje

Hallo, ik ben pas begonnen met Arduino, ik heb wel ervaring met PIC controllers in assembler en wilde toch wel eens meer weten over Arduino. Nu had ik met een PIC een thermometer gemaakt met een Nokia5110 LCD display, het leek me een leuk idee om te kijken of ik dat ook op een Arduino zou kunnen. En inmiddels is het gelukt, veel trail en error. Verder is Arduino een goed doordacht concept, veel low level zaken worden voor je gedaan en alles open source, ik wil graag het eertse succesje delen op dit forum. Ik hoop dat dat mag op dit forum. Mischien hebben andere mensen er nog iets aan.

De thermometer werkt met een Display van Nokia een nokia 5110, die zijn voor een paar dollar in China te koop via Ebay. Deze display werkt op 2,7 tot 3,3 Volt dus kan niet direct op de 5 Volt van de arduino UNO. Ik heb er een levelschifter tussen gezet die de logische niveaus terug brengt naar 3,3 volt. Heb je een volledig 3,3 volt systeem dan kan deze levershifter vervallen. Let wel op, er zijn verschillende printjes in omloop, met name de backlight aansluitingen kunnen anders zijn dan in mijn schema. Sommige moeten juist naar de plus geschakeld worden. Als temperatuursensor is de Dallas DS16B20 gebruikt, een one-wire sensor, ik heb een bestaande one-wire library gebruikt in dit project. Het is echt als hobby projectje bedoeld, er zal zeker nog veel aan te verbeteren zijn maar ik vind het al leuk dat het werkt. Het is ook mijn eerste post dus ik hoop dat het goed te zien/lezen is.

Het resultaat :

De code posten lukt mij niet, ik kreeg een waarschuwing dat ik over het aantal toegestane karakters zat.

Rindkmp
Welkom op het nederlandse gedeelte van het arduino forum.
Je eerste post mag er wezen. Direct een afgewerkt voorbeeld projectje. Waar zit jij ergens dat het nu zo koud is :wink:
Met vriendelijke groet
Jantje

Bedankt, als je goed kijkt zie je rechts draden uit het beeld gaan, daar zit de sensor aan en ligt tegen een doosje uit de vriezer :slight_smile: Ik moest toch testen wat ie zou doen onder nul.

Leuk projectje, goed uitgewerkt ook! Misschien kan je je code alsnog posten in een nieuwe post. Mochten mensen met dezelfde componenten werken komen ze via google alsnog op dit topic.

Ok, zal een poging doen de code te posten, dit is het eerste deel (de hoofdroutine) :

/*
Thermometer using a Nokia 5110 LCD display and a DS18B20 Temperature sensor.
Temperature is shown in big digits on the LCD display with one decimal.
If it's below zero the word "MIN" is displayed on the top of of the display
DS18B20 Code from http://bildr.org/2011/07/ds18b20-arduino/
*/

#include <avr/pgmspace.h>
#include <OneWire.h>

#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN  4
#define PIN_SCLK  3
                   
#define LCD_C     LOW
#define LCD_D     HIGH

#define LCD_X     84
#define LCD_Y     48
#define LCD_CMD   0

// Onboard LED on pin 13 
int led = 13;

//DS18S20 Signal pin on digital 10
int DS18S20_Pin = 10;
OneWire ds(DS18S20_Pin);

int  tens = 0;
int  ones = 0;
int  deci = 0;
long store = 0;


void setup()
{
  LcdInitialise();    
  LcdClear();
  pinMode(led, OUTPUT);    // On board LED as output
  Serial.begin(9600);
  PlaceComma();
  PlaceCelcius();
}

void loop()
{
  float temperature = getTemp();                   // Do temperature measurement
  Serial.println(temperature);                     // Output temperature to serial port
  
  if (temperature < 0)                             // Display MIN word if temp is below 0
  { PlaceMinWord(true);}
  else
  {PlaceMinWord(false);}
  
  temperature = abs (temperature);                 // Convert temperature to positiv value
                                                   // to calculate the separate digits
  
  tens = temperature / 10;                         // Calcultate the tens
  if (tens != 0) {PlaceDigit(tens, true, 0, 2);}   // Place Tens digit on LCD
  if (tens == 0){PlaceDigit(tens, false, 0, 2);}   // Blank Tens digit on LCD     
  
  ones = temperature - (tens*10);
  ones = abs(ones);                               // Calcultate the ones
  PlaceDigit(ones, true, 20, 2);                  // Place Ones digit on LCD

  store = (10*tens) + ones;                       // Calcultate the deci
  temperature = temperature * 100;
  temperature = temperature - (store*100);
  temperature = temperature / 10;
  deci = abs (temperature);
  PlaceDigit(deci, true, 46, 2);                  // Place Deci digit on LCD

  digitalWrite(led, HIGH);                        // On board LED blinks during the wait 
  delay(500);               
  digitalWrite(led, LOW);    
  delay(500);               
}

// Include the tables for the dotmatrix characters
#include "dotmatrix_table.h";

// Place the Celcius symbol on the display
void PlaceCelcius()
{
  unsigned int displayInt;
  gotoXY(66,2);                                   // set position on LCD for top row

  for (int x = 0; x < 18; x++) 
    {
    displayInt = pgm_read_word_near(Celcius + x); // Read bytes from table
    LcdWrite (LCD_D, displayInt);                 // Write byte to display
    } 

  gotoXY(66,3);                                   // set position on LCD for bottom row

  for (int x = 0; x < 18; x++) 
    {
    displayInt = pgm_read_word_near(Celcius + x + 18 ); // Read bytes from table
    LcdWrite (LCD_D, displayInt);                       // Write byte to display
    } 
}


// Place comma on the LCD display
void PlaceComma()
{
  unsigned int displayInt;
  gotoXY(40,5);                                 // set position on LCD

  for (int x = 0; x < 4; x++) 
    {
    displayInt = pgm_read_word_near(Comma + x); // Read bytes from table
    LcdWrite (LCD_D, displayInt);               // Write byte to display
    } 
}

// Initialise LCD display
void LcdInitialise(void)
{
  pinMode(PIN_SCE,   OUTPUT);
  pinMode(PIN_RESET, OUTPUT);
  pinMode(PIN_DC,    OUTPUT);
  pinMode(PIN_SDIN,  OUTPUT);
  pinMode(PIN_SCLK,  OUTPUT);

  digitalWrite(PIN_RESET, LOW);
  delay(1);
  digitalWrite(PIN_RESET, HIGH);

  LcdWrite( LCD_CMD, 0x21 );  // LCD Extended Commands.
  LcdWrite( LCD_CMD, 0xc2 );  // Set LCD Vop (Contrast).
  LcdWrite( LCD_CMD, 0x04 );  // Set Temp coefficent. 
  LcdWrite( LCD_CMD, 0x13 );  // LCD bias mode 1:48.
  LcdWrite( LCD_CMD, 0x0C );  // LCD in normal mode.
  LcdWrite(LCD_C, 0x20);
  LcdWrite(LCD_C, 0x0C);      // LCD in normal mode. 0x0d for inverse
}

//Write data to LCD display
void LcdWrite(byte dc, byte data)
{
  digitalWrite(PIN_DC, dc);
  digitalWrite(PIN_SCE, LOW);
  shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
  digitalWrite(PIN_SCE, HIGH);
}

// gotoXY routine to position cursor 
// x - range: 0 to 84
// y - range: 0 to 5

void gotoXY(int x, int y)
{
  LcdWrite( 0, 0x80 | x);  // Column.
  LcdWrite( 0, 0x40 | y);  // Row.  
}


// Clear LCD Display
void LcdClear()
{
  for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
  {
    LcdWrite(LCD_D, 0x00);
  }
}

// Place digit op LCD display
// Use blanking value to switch to the digit on or off
void PlaceDigit(int digit, boolean blanking, byte posx, byte posy)
{
  byte displayByte;
  word offset;
//  byte posx = 0;
//  byte posy = 2;

  offset = digit * 72;
  
   for (int y = 0; y < 4; y++){ 
    gotoXY(posx, posy); 
     for (int x = (y*18); x < (y*18)+18; x++) 
          {
          displayByte = pgm_read_word_near(Digits + offset + x );
          if (blanking == true) {LcdWrite (LCD_D, displayByte);} 
          if (blanking == false) {LcdWrite (LCD_D, 0x00);}     
          } 
      posy++;  
  }
}

// Place the word "MIN" on the top line of the display
// Use blanking value to switch to the word on or off
void PlaceMinWord(boolean blanking)
{
  byte displayInt;
  gotoXY(27,0);     // set position on LCD for top row
  
  for (int x = 0; x < 28; x++) // Read bytes from table and write it to the dipslay  
    {
    displayInt = pgm_read_word_near(MinWord + x);
      if (blanking == true) {LcdWrite (LCD_D, displayInt);} 
      if (blanking == false) {LcdWrite (LCD_D, 0x00);}     
    } 

  gotoXY(27,1);     // set position on LCD for bottom row

  for (int x = 0; x < 28; x++) // Read bytes from table and write it to the dipslay  
    {
    displayInt = pgm_read_word_near(MinWord + 28 + x);
      if (blanking == true) {LcdWrite (LCD_D, displayInt);} 
      if (blanking == false) {LcdWrite (LCD_D, 0x00);}     
    } 
}

//Get temperature from temp sensor
float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad

  
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
  
  ds.reset_search();
  
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
  return TemperatureSum;
}

En dit de header file met daarin de character tables (dotmatrix_table.h).
Deze open je in een extra tabblad.

// Bytes to display the celcius symbol
PROGMEM  prog_uchar Celcius[]  = { 0x60,0xF0,0x08,0x0C,0x0C,0x08,0xF0,0x60,0x00,0xE0,0xF0,0x38,0x0C,0x0C,0x0C,0x0C,0x38,0x30,
                                   0x00,0x00,0x01,0x03,0x03,0x01,0x00,0x00,0x00,0x0F,0x3F,0x70,0xC0,0xC0,0xC0,0xC0,0x70,0x30 };
                                   
// Bytes to display the comma
PROGMEM  prog_uchar Comma[]    = { 0x0F, 0xCF, 0xFF, 0X3F };


// Bytes to display the word "MIN"
PROGMEM  prog_uchar MinWord[]  = { B11111110,  B11111110,  B00111100,  B11110000,  B11000000,  B11000000,  B11110000,  
                                   B00111100,  B11111110,  B11111110,  B00000000,  B00000000,  B00000110,  B11111110,  
                                   B11111110,  B00000110,  B00000000,  B00000000,  B11111110,  B11111110,  B00011100,  
                                   B01111000,  B11100000,  B10000000,  B00000000,  B00000000,  B11111110,  B11111110,
                                   B01111111,  B01111111,  B00000000,  B00000000,  B00000011,  B00000011,  B00000000,  
                                   B00000000,  B01111111,  B01111111,  B00000000,  B00000000,  B01100000,  B01111111,  
                                   B01111111,  B01100000,  B00000000,  B00000000,  B01111111,  B01111111,  B00000000,  
                                   B00000000,  B00000001,  B00000111,  B00011110,  B00111000,  B01111111,  B01111111 };



// Bytes to display the digits 0 to 9
PROGMEM  prog_uchar Digits[]   = { 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00,
  				   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
                                   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
                                   0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00,
                                   0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xF0, 0xF0, 0xFC, 0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                   0xC0, 0xC0, 0xF0, 0xF0, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xFC, 0xFC, 0xF0, 0xF0, 0xC0, 0xC0,
                                   0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xF0, 0xF0, 0xFF, 0xFF, 0x3F, 0x3F,
                                   0x00, 0x00, 0xF0, 0xF0, 0xFC, 0xFC, 0x3F, 0x3F, 0x0F, 0x0F, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00,
                                   0x3F, 0x3F, 0x3F, 0x3F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C,
                                   0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00,
                                   0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xF0, 0xF0, 0x3F, 0x3F, 0x0F, 0x0F,
                                   0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x0F, 0x0F, 0xFF, 0xFF, 0xF0, 0xF0,
                                   0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0xC0, 0xC0, 0xFC, 0xFC, 0x3F, 0x3F, 0x03, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
                                   0xFC, 0xFC, 0xFF, 0xFF, 0xF3, 0xF3, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0xFC, 0xFC, 0xFC, 0xFC, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00,
                                   0x3F, 0x3F, 0xFF, 0xFF, 0xF3, 0xF3, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00,
                                   0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0xFF, 0xFF, 0xFC, 0xFC,
                                   0x03, 0x03, 0x0F, 0x0F, 0x3F, 0x3F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00,
                                   0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00,
                                   0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xC0, 0xC0, 0xC3, 0xC3, 0x03, 0x03,
                                   0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0xFF, 0xFF, 0xFC, 0xFC,
                                   0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00,
                                   0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xFC, 0xFC, 0xFC, 0xFC,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xFC, 0xFC, 0x3F, 0x3F, 0x03, 0x03,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0xFF, 0xFF, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00,
                                   0x0F, 0x0F, 0x3F, 0x3F, 0xF0, 0xF0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xF0, 0xF0, 0x3F, 0x3F, 0x0F, 0x0F,
                                   0xF0, 0xF0, 0xFF, 0xFF, 0x0F, 0x0F, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x0F, 0x0F, 0xFF, 0xFF, 0xF0, 0xF0,
                                   0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00,
                                   0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00,
                                   0x3F, 0x3F, 0xFF, 0xFF, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF,
                                   0xC0, 0xC0, 0xC3, 0xC3, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFF, 0xFF, 0xFF, 0xFF,
                                   0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00 };