Thursday, October 7, 2010

Analog Switch Expands I2C Interface

What to do when you have two I2C devices with the same address? Need additional I2C channels? Here's a easy to use analog switch to enable 3 separate I2C channels. A MAX4562 and a handful of pullup resistors might be the ticket.

http://www.maxim-ic.com/app-notes/index.mvp/id/955

Wednesday, October 6, 2010

Real Time Clock Shield

We have been working on our Real Time Clock and LCD display as a snap on "shield" (no wiring). This will provide not only a time date function, but clock and display functions to other projects. We ran across another similar project at http://tronixstuff.wordpress.com/2010/10/07/add-a-real-time-clock-to-the-freetronics-twentyten/

Good stuff there, check it out.

Sunday, October 3, 2010

DS1307 Real Time Clock Working

With a bunch of help from John Boxall of Tronixstuff.com, we finally got the Time / Date functions working on our Arduino, with the DS1307 breakout board from Sparkfun. Thanks John.

More info at http://www.instructables.com/id/The-Arduino-Weather-Station-Thermostat/step6/Arduino-Clock-Module/

Finished code and wiring is below:

// Connections:
// LCD pin 1 to Arduino GND
// LCD pin 2 to Arduino 5v
// LCD pin 3 (Contrast) to GND
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pin 16 to Arduino GND
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2

//Tested with DS1307 Breakout from Sparkfun
//pin SDA to Arduino Analog pin 4
//pin SCL to Arduino Analog pin 5
//pin GND to Arduino GND
//pin VCC to Arduino 5v


#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#include <LiquidCrystal.h> // we need this library for the LCD commands
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int backLight = 13; // pin 13 will control the backlight

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup()
{
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 0;
minute = 42;
hour = 9;
dayOfWeek = 1;
dayOfMonth = 3;
month = 10;
year = 10;

//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
lcd.begin(16, 2); // tells Arduino the LCD dimensions

}
void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.clear(); // clear LCD screen
lcd.setCursor(0,0);
lcd.print(" ");
lcd.print(hour, DEC);
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(0,1);
lcd.print(" ");
switch(dayOfWeek){
case 1:
lcd.print("Sun");
break;
case 2:
lcd.print("Mon");
break;
case 3:
lcd.print("Tue");
break;
case 4:
lcd.print("Wed");
break;
case 5:
lcd.print("Thu");
break;
case 6:
lcd.print("Fri");
break;
case 7:
lcd.print("Sat");
break;
}
lcd.print(" ");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(dayOfMonth, DEC);
lcd.print("/20");
lcd.print(year, DEC);
delay(1000);
}

Saturday, October 2, 2010

Arduino Mega 2560 Operational!

I ported our temp / humidity (and not quite right barometric pressure) project over to the Mega 2560 a few minutes ago. So many more I/O pins. I love it! Will continue working on time date functions, and getting the barometric pressure reading sorted out. Once I get the BP working, I have to figure out code that will take comparative readings, and show rising or falling symbols.

Barometric Pressure, Real Time Clock, and Mega 2560 Woes

Today is Arduino day. First off, I grabbed the new BMP085 module from Sparkfun, and modified the examples to talk to my lcd instead of serial output. It's displaying

"Temperature -2678 Pressure 52029"

which can't be right, so I whipped off a email to Sparkfun tech support for some guidance. Then I grabbed the DS1307 real time clock module from Sparkfun, and again changed the code to display on my lcd (what's with all the serial output code folks? I don't want to have my laptop up just to see the time). Got

0:0:0 0/0/0

which also isn't right. Found a website which claimed their code works with lcd, so I uploaded their sketch. My pin 13 LED started flashing, and now can no longer upload code to my Arduino Duemilanove 328P. All I get is

"avrdude: stk500_recv(): programmer is not responding"

I rebooted my laptop, and no change. Ok, time to pull out the new Arduino Mega 2560. Oh, wait! No, that requires IDE version 0020, which isn't available for linux yet.

I'm going to go watch some tv ......

Update: 20 minutes after I posted this, The folks at Arduino posted version 0021 of the IDE, which includes the linux version. Yeehaw!