Since I bought the Arduino Uno board, I bought several shields and electronic kits/modules for arduino that were interesting to me. I got motor shield, Ethernet shield, serial port shield, RTC/EEPROM I2C module, SD card module (SPI), LCD/keypad shield, I2C 20x4 LCD module, another Arduino board (a clone that was included in some bundle) and I am still waiting for Arduino Mega board. This stuff is amazingly cheap and easy to put together and getting to work. Using widely available code examples from internet, arduino web site, arduino IDE or included with the shields/modules that I bought, I was able to test all the modules above in 2 short evening sessions. Just a little bit of soldering was required with some of the shields and modules since some of them arrived in the form of partially assembled kits or with soldering holes for optional pins or sockets.
As an example, I present you with this nice sandwiched circuit, consisting of Arduino Uno R3 board, serial port shield sitting on top of it, the LCD/keypad shield sitting on top of the serial port shield and the I2C RTC/EEPROM module sitting in the socket I soldered into the LCD/keypad module. It took me just few hours to learn this stuff, collect and write the code, solder extra pins and sockets and put it all together:
The program it runs is just a test of RTC module. The date/time is displayed on the LCD and also sent over the serial port:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
/*
The LCD circuit:
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD BL pin to digital pin 10
* KEY pin to analogl pin 0
*/
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
RTC_DS1307 RTC;
boolean bBlink = true;
void setup () {
// initialize LCD keypad module
lcd.clear();
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("RTC test");
// power to i2c_ds1307_at24c32 module provided via A2, A3 pins
pinMode(A3, OUTPUT);
digitalWrite(A3, HIGH);
pinMode(A2, OUTPUT);
digitalWrite(A2, LOW);
// start communication, I2C and RTC
Serial.begin(9600);
Wire.begin();
RTC.begin();
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();
lcd.setCursor(0,1);
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(' ');
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
if (bBlink)
{
lcd.print(':');
bBlink = false;
}
else
{
lcd.print(' ');
bBlink = true;
}
Serial.print(" since 1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.unixtime() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(1000);
}
For the rapid project development or ad-hoc circuit testing, Arduino is a great platform that also more technically sophisticated audience can use. Definitely not only for artists and kids learning electronic, as it is categorized by some.
Arduino will stay in my toolbox for the time to come.
Credits:
I used code samples from following sources:
DS1307 RTC tutorial.
Code sample from eBay listing of Keypad Shield 1602 LCD For Arduino MEGA 2560 1280 UNO R3 A005.
Marek Karcz
2012/12/08
No comments:
Post a Comment