Categories
Arduino Creative Geekery

Countdown to Christmas with the Arduino advent calendar!

This year, as part of the publicity for their Christmas charity gifts, Concern Worldwide (who I’m lucky enough to work for) commissioned an artist to come up with a design for an advent calendar.

The resulting design by Robert Fiszer is really rather lovely (you can check out the campaign here)- and lends itself rather well to be illuminated as a Christmas decoration for the Concern office.

Concern Advent Calendar designed by Robert Fiszer
Concern Advent Calendar designed by Robert Fiszer

So as a spare tinkering time project I thought I would have a go at building an Arduino controlled LED advent calendar that illuminates the relevant day and counts down to the 24th.

My requirements needed it to be powered by USB, and that it’s a standalone project with it’s own date clock – as the office IT department would frown upon me installing things on my work PC to run Christmas decorations from. In order to do this I needed to read up on using a battery backed up RTC (Real Time Clock) and a way to control 24 LEDs from my arduino micro.

I decided on using a shift register – the other option would be to use a chain of NeoPixel LEDs, but I wanted to learn about shift registers and get an idea about how they worked. For an excellent introduction to shift registers check out this blog from Bildr.

Essentially a shift register is a way of converting a serial signal from the arduino into a parallel series of high and low signals to the output pins on each chip. Each shift register has 16 pins, 8 output pins, 2 earth pins, 2 positive 5 volt pins, 3 serial input pins consisting of clock, latch and time signals, and a final serial output pin which is used when daisy chaining them together.

The 74HC595 8-bit Shift Register I used was available cheaply on ebay and looks like this:

My diagram of a shift register
There are better diagrams out there but this helped me

Wired up with an arduino on breadboard it looks like this:

Teaching myself about shift registers and Larson scanners #arduino #kitt #cylon

A video posted by Pete Taylor (@kimondouk) on

Even with just 8 outputs it looks a bit messy. With 3 shift registers daisy chained together it looks even more complicated:

Now with 3 shift registers and 24leds #arduino #adventcalendar

A video posted by Pete Taylor (@kimondouk) on

But remember the diagram above – the circuit is still fairly simple, what makes it look complicated is the loops of wire which are all the same length. The challenge I found with the chip is that one of the outputs is on one side, with the remaining 7 on the other.

To tidy everything up, I soldered the chips in carriers onto a piece of full sized Adafruit perma-proto breadboard. I highly recommend using this stuff – it costs a bit more than the generic soldering boards you can buy on ebay, but it’s strong and laid out sensibly using the same layout as standard prototyping boards. In my layout I spaced the shift registers 1 hole apart and moved the offside output around the corner of the chip, so that all 8 outputs were on the same side. To connect my LEDs I was able to add 8 socket female headers as I found soldering the LED wires directly into the board was difficult as the stranded copper wire would snap easily. Plus using headers gives me the option to swap out the LEDs for something else in the future. For LEDs I found pre-soldered 5 volt LEDs available on ebay that included the resistor.

My board includes 4 shift registers giving me a total of 32 outputs – this would enable me to re-purpose the board in future, as I’m thinking after advent it would make a nice monthly calendar.

Here’s the board without any of the LEDs attached:

Shift register without the LEDs
Shift register without the LEDs

For the time circuit I used a DS 1307 RTC – the one I used shares the same chipset as the Adafruit one detailed here (link) (normally I’d buy the adafruit one to support their website, but I couldn’t find it available online).

The code:

/*
Shift register calendar
*/

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)  // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

// shift register setup

//**************************************************************//
//  Name    : shiftOutCode, Dual One By One                           //
//  Author  : Carlyn Maw, Tom Igoe                               //
//  Date    : 25 Oct, 2006                                       //
//  Version : 1.0                                                //
//  Notes   : Code for using a 74HC595 Shift Register            //
//          : to count from 0 to 255                             //
//**************************************************************//


int SER_Pin = 4;   //pin 14 on the 75HC595
int RCLK_Pin = 5;  //pin 12 on the 75HC595
int SRCLK_Pin = 6; //pin 11 on the 75HC595

int caldate = 0;

//How many of the shift registers - change this
#define number_of_74hc595s 4

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

void setup() 
{
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);


  //reset all register pins
  clearRegisters();
  writeRegisters();

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  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(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 6, 2014 at 3am you would call:
    //   rtc.adjust(DateTime(2014, 1, 6, 3, 0, 0));
  }
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
  writeRegisters();
} 


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)

void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}


void loop() 
{
  DateTime now = rtc.now();
  caldate = now.day();
  Serial.print(caldate);
   Serial.print(now.day(), DEC);
 
  delay(1500);
  clearRegisters();
  delay(500);

  for (int i = 0; i < caldate; i++)
  {
   setRegisterPin(i, HIGH);
   writeRegisters();
  delay(100);
  }
}

Note – the RTC was the trickiest part of the circuit, and after reading lots of posts from people who’ve had issues with the DS1307 I’d recommend using one of the integrated chip varieties.

The code for the calendar is fairly simple – it checks the date from the RTC and then lights up the appropriate number of lights. I’ve made it loop to give a bit more visual interest, but it’s easy enough to modify the code to make it just light up once when you plug it in.

Assembly

I printed out the calendar image and pasted it onto a bit of board with holes behind each ‘light’. Using a frame from a previous project (the Concern general election Swingometer) to bring it all together. To mount the LEDs I used bottle tops – this involved drinking a lot of diet coke, and when I ran out of that, wine.

Back of the advent calendar
Back of the advent calendar

Here’s the final version, in action as if it’s Christmas Eve showing all the lights as I removed the RTC.

The #arduino shift register powered #adventcalendar is now finished! Happy #1stdecember

A video posted by Pete Taylor (@kimondouk) on

If you liked this project, please buy a gift from Concern’s shop – my personal favourite is the solar lights as they are a neat technological solution to the tricky problem of lighting.

Categories
Creative Family Geekery Raspberry Pi

5 geeky DIY Christmas gift ideas

With Christmas rapidly approaching, one of my aims this year is to at least attempt a bit of DIY Christmas gifting. So if you know me, there are potential spoilers ahead and stop reading this right now. So here are five ideas I may or may not be considering as part of my Christmas gift ideas. These really are quite geeky, but then so are most of my friends and family.

1. 3d printed jewellery

We don’t all own 3d printers (yet) particularly ones that can print in precious or semi-precious metals. But head over to Shapeways – a website with a name that sounds like it’s straight from an episode of the Hitch-hikers Guide to the Galaxy and you can print more or less anything you can practically design provided it’s in a format they support. You can also order a printed version of your idea in cheaper plastic before committing to a more expensive material.

For a less daunting project you can contact some of the designers to create customised versions of their work. Lots of designs are available on Thingiverse for you to download and edit (including the ring shape below).

http://www.thingiverse.com/thing:7354
Thingiverse Ring, it’s a thing.

2. Make your own lego brick shaped bath bombs

So slightly less technical but fun nevertheless is to make your own bath bombs or fizzies. These are compacted cubes of Sodium Bicarbonate and Citric Acid that bubble Carbon Dioxide when you chuck them in the bath:

C5H7O5COOH + NaHCO3 → C5H7O5COONa+ + H2O + CO2

Here’s a nice recipe from Busy City Mum’s blog for Bath Fizzies which goes into detail about what quantities and ingredients you need. You can now buy silicon moulds in lots of shapes including Lego brick (lookalikes, not official) and the Death Star (not a moon).

In Japan it’s tradition to include a figure inside the bath bomb, so a Lego minifigure would seem appropriate!

3. A custom Raspberry Pi

A very neat little computer

 

I had to include a Raspberry Pi based project – there are lots to choose from including Media players and retro computer emulators – but for this I wanted to find something that would be suitably difficult to purchase. One possibility is the Raspberry Pi magic mirror which is detailed on it’s creator’s blog – this is something you simply can’t buy, and looks amazing – although you’ll need a monitor and a mirror for the full effect.

My simpler project is to build a Raspberry Pi audio streamer. Audio streamers are generally very expensive and although the Pi’s default audio output is fairly basic it’s possible to add a DAC to provide really high quality sound output. Thanks to Carla at busycitymum.com for sending me a Wolfson Pi I was able to build a fairly decent Pi Music Box with Airport support.

The recipe for this is as follows – I’ve confirmed this to work with the original Wolfson Pi Audio Card and a Raspberry Pi model A – there is a new version of the Wolfson card available for the newer Raspberry Pi models.

  • Download the custom version of Raspbian from www.element14.com/PiAudioCard – on the Mac the custom version of Raspbian unpacks best if you use Stuffit Expander and then Apple Pi Baker to copy the iso file to an SD card.
  • Install Shairport using these instructions from Drew Lustro
  • For a final bit of polish (particularly if your running a Raspberry Pi as a headless server) you can include a web based shutdown control panel – follow the instructions on the forum here. You can edit the web page to include a nice message to your gift recipient as well!
IMG_2679
Raspberry Pi Airport speaker

DIY projects that work with Apple products go down quite well.

4. Bake!

Baking is a much appreciated gift – and given the diversity of cookie cutting shapes available it’s possible to give a nerdy spin on even the most traditional recipes.

Firebox do a nice line in Tetris Cookie cutters – combined with a Gingerbread recipe these make for a pleasing tessellating gift.

I’ve tried a few different gingerbread recipes and Delia’s is by far the best. Thanks to the additional spoon of black treacle the gingerbread is sufficiently biscuity – and you can vary the cooking time if you want a more chewy gingerbread. Other recipes don’t work as well since they opt for either golden syrup or black treacle. Cowards.

Combine with an original Gameboy (search for DMG1) for added wow factor. Works particularly well on millennials.

Gingerbread Tetris
Gingerbread Tetris

5. Give a DIY gift

So technically cheating, but you can also give the gift of DIY. I recently reviewed the StoneTurners DIY microscope

finished USB microscope
I was a little heavy with the glue gun

which can take awesome pictures of things, and works with the Raspberry Pi.

If you want to spend a bit more the DIY projects from Technology will save us are worth a look.  Although they’re more expensive than shopping around and buying the parts, the packaging is lovely and they make quite complicated projects accessible. Plus angry birds on the Arduino is very addictive…