006 Restored the original demo of EvB4.3 board

1. Forewords

The goal is to restore the original demo application which come with the EvB4.3 boards. Unfortunately, the resulted code is not optimized and will require at least ATmega32 micrcontroller inserted on the board.  But don't forget that the entire set of tutorials for this board, using Arduino language, are for the ATmega644P micrcontroller. Of course, the application can be written on other compilers/languages and can be much smaller and faster.

2. Setup the board

--- to be completed ---

3. The Sketch

#include <IRremote.h>
#include <Wire.h> // necessary, or the application won't build properly #include <stdio.h>  #include <PCF8583.h>  #include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/*****************************************************************************  *  Restoring the original demo app. which come with EvB4.3 boards  *  *  You can set the time by sending it YYMMDDhhmmss; from console.  *  The semicolon on the end tells it you're done...  *  ******************************************************************************/ // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.  DallasTemperature sensors(&oneWire);
 
 
int RECV_PIN = 1;
int STATUS_PIN = 13;
IRrecv irrecv(RECV_PIN);
decode_results results;

int correct_address = 0;
PCF8583 p (0xA2);// the device's I2C read address on our board LiquidCrystal lcd(22, 23, 24, 25, 26, 27);

void setup(void){
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver   // set up the LCD's number of columns and rows:   lcd.begin(16, 2);
  pinMode(STATUS_PIN, OUTPUT);
  // Start up the library   sensors.begin();
}

// Storage for the recorded code int codeType = -1; // The type of code void showCode(decode_results *results) {
  codeType = results->decode_type;
  //int count = results->rawlen;   if (codeType == RC5) {
    Serial.print("Received RC5: ");
    // the workaround     if (results->value >= 0x800) {
      results->value = results->value - 0x800;
    }
    // end workaround     Serial.println(results->value, HEX);
    lcd.setCursor(14, 0);
    lcd.print(" ");
    lcd.setCursor(14, 0);
    char date[3];
    sprintf(date, "%2X", results->value);
    lcd.print(date);
  } 
  else{
    Serial.println("Received different code!");
  }
}


void loop(void){
  //reading time setup from the serial console   if(Serial.available() > 0){
       Serial.println("receiving...");
       p.year= (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)) + 2000;
       p.month = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
       p.day = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
       p.hour  = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
       p.minute = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
       p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));
// Use of (byte) type casting and ascii math to achieve result.        if(Serial.read() == ';'){
         Serial.println("setting date");
 p.set_time();
       }
  }
  //   p.get_time();   char date[9];
  sprintf(date, "%02d/%02d/%02d",
  p.year, p.month, p.day);
  lcd.setCursor(0, 0);
  lcd.print(date);
  lcd.print(" IR:");
  // print IR RC5 code   //digitalWrite(STATUS_PIN, HIGH); //switch off the LED on our board (common anode)   if (irrecv.decode(&results)) {
    digitalWrite(STATUS_PIN, LOW);
    showCode(&results);
    irrecv.resume(); // resume receiver     delay(50);
    digitalWrite(STATUS_PIN, HIGH); //switch off the LED on our board (common anode)   }    //   char time[9];
  sprintf(time, "%02d:%02d:%02d",
  p.hour, p.minute, p.second);
  //Serial.println(time);   lcd.setCursor(0, 1);
  lcd.print(time);
  lcd.print(" T:");
  // call sensors.requestTemperatures() to issue a global temperature   // request to all devices on the bus   sensors.requestTemperatures(); // Send the command to get temperatures   lcd.print(sensors.getTempCByIndex(0));
}

4. The Result

The green LED indicate when an IR code is received. On LCD are displayed date, time, temperature and RC5 IR code.


And with this, our fist target is achieved!!!

Comments

Translation

Recent site activity