Tag Archives: pocketmoon

Interfacing with Adafruit’s Atmel-powered Trinket



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.

How much you can hang off a Trinket (ATtiny85)?

Adafruit’s Trinket platform – based on Atmel’s versatile ATtiny85 microcontroller (MCU) – has been used to power a number of diverse projects in recent months, including an audio playerflickering candle in a jar, a knock drawer lock, a sound-reactive LED color organ and even a rover.

Today, we’re going to take a closer look at an Adafruit forum post by Pocketmoon who wanted to demonstrate just how many components can be hung off the 3.3v ATtiny85-powered Trinket.

Over I2C

  • DS1307 Real Time Clock (includes 24C32 32K Bit I2C EEPROM memory which is also visible on the I2C bus)
  • HMC5883L 3 Axis Compass Magnetometer
  • PCF8574 – Remote 8-Bit I/O Expander for I2C-Bus

Over SPI

  • OLED 128×64 SSD1306
  • 23K256 SRAM Chip – 32K of lovely SPI accessible memory.

“The SRAM provides a screenbuffer for the OLED module, which has no built in RAM. To draw the buffer to the display I read a ‘page’ worth of data (128 Bytes) at a time from the framebuffer and push these to the OLED, both over SPI. So a local 128 byte buffer is needed in the Trinket. All the Trinket pins are in use so I use a small switch to disconnect #3 and #4 during programming,” Pocketmoon explained.

“With SPI you need a separate Slave Select line for each device. These are provided by the PCF8574 which is an I2C IO Expander. I write to this first (over I2C) to select one of the output pins which act as Slave Selects for each SPI device. The outputs (I’m using 2) are then AND’ed with a single Master SS (on #3). This allows the individual SS’s to be driven low by the master SS. Code eequires a bit of jumping between I2C mode and SPI mode and both are using the serial hardware on the ATtiny.”

The display in the photo above shows the time, a compass reading and a time per frame in milliseconds. Pocketmoon says the display is running at about 13fps, with additional room for optimization.

Interested in learning more? You can check out the original forum post here and pick up a Trinket from Adafruit’s official store here for $7.95.