Bits & Pieces recently covered a project by a Maker named Pocketmoon who wanted to demonstrate just how many components can be hung off Adafruit’s 3.3v ATtiny85-powered Trinket.
Today, we’re going to be taking a closer look at constructing a Trinket RGB shield clock, courtesy of the Adafruit crew. According to Adafruit’s Mike Barela, the project was inspired by a forum member who asked if the Trinket can be interfaced with an RGB LCD shield, which was originally designed to link with more “classic” Arduino boards using a standard shield pin layout.
“Obviously the shield cannot stack onto Trinket but with four wires, the display shield can hook up to a Trinket project well. This is accomplished as both use the I2C or two-wire bus to communicate,” Barela explained in detailed tutorial. “As a further demonstration, the Adafruit I2C based DS1307 real-time clock module is used to display the time and date. The display shield’s buttons allow for changing the hour in case of daylight savings time and toggle the backlight.”
Before kicking off the project, Makers will need to download three code libraries (TinyWireM, TinyRTClib, TinyAdafruit_RGBLCDShield) all optimized for Atmel’s ATtiny85 microcontroller (MCU) powering the Trinket. Next up? Modifying the Arduino IDE to work with Trinket by adding the hardware definition file, the avrdude.conf file, changing the ld.exe program (or download the preset Arduino 1.05 from Adafruit).
“Since we’re using I2C for the shield and real time clock, hookup is fairly straightforward,” said Barela.
“Don’t forget, I2C allows you to use multiple devices on two shared pins, perfect for when you don’t have a lot of pins like the Trinket.”
On the code side of things, Barela uses two programs are used to save space. The first, typically runs once (initialization) and sets the battery-backed DS1307 RTC, while the main code displays the clock value and polls the buttons. Meaning, if the up or down buttons are pressed, the value offset is incremented/decremented. This is added to the RTC clock time to form the hour.
“The combination of Trinket and the RGB LCD Shield is a good combination for display and input. There is enough code space to hook a number of sensors for real-time readout,” Barela concluded. “If you believe the shield form factor is not ideal, use of the LCD with the I2C backpack is a good combination. See the tutorial for the Trinket Ultrasonic Rangefinder as an example. If you want a more precise clock, you can swap the DS1307 for a Chronodot, it is code-compatible and ultra-precise!”
Interested in learning more? You can check out Adafruit’s detailed tutorial here.