Twitter based Christmas ornaments update

When we introduced you to the Twitter Christmas tree ornaments, sadly we had very little information about the project. Luckily [Rob] made contact and clued us in on the inner workings. It even turns out we were wrong about the usage of Arduinos! We invite you to check out all the juicy inner workings after the break.

Lets jump right into the explanation,

So the controller uses a single Arduino connected to 3 74HCT595 shift registers.  The ‘595 takes a clock bit and a data bit, and each leading edge (0-1 transition) of the clock bit shifts in a data bit.  Then there’s an 8-bot latch, and the leading edge of another line captures the state of the shift register to the outputs.  Each ‘595 stores 8 bits, can be chained, and there are three of them.  This lets it control 24 lights with only 3 I/O lines.  Each output is connected to a TIP31 transistor, in standard NPN configuration.  The TIP31 can switch up to 3A, so they handle the 1A 6V lamps with no problem.  This is pretty close to the schematic we’re using, except only 24 outputs:

Here’s the sketch I used to control the shift registers:

long count;
unsigned long val;
void setup()
{
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);

  count = 0x00;
  val = 0;
}

void loop()
{
  unsigned long i;

  if (Serial.available())
  {
    char c = Serial.read();
    if (c >= '0' && c <= '9') {
      val = val * 10 + (c - '0');
      Serial.print(c);
    } else if (c == '\n')
    {
      Serial.print("setting count to ");
      Serial.println(val);
      count = val;
      val = 0;
    }
  }

  unsigned long bv;
  digitalWrite(10, LOW);
  for (i=0, bv=1; i < 24; ++i, bv <<= 1)
  {
    byte bitval = LOW;
    if (count & bv)
      bitval = HIGH;
    //Serial.print("i ");
    //Serial.print(i);
    //Serial.print(" bit ");
    //Serial.println((int)bitval);

    digitalWrite(11, bitval);
    digitalWrite(13, HIGH);
    delayMicroseconds(50);
    digitalWrite(13, LOW);

    delayMicroseconds(50);
  }
  digitalWrite(10, HIGH);

    delay(10);
    //++count;
    //count &= 0x3ff;
}

I bit-banged the SPI protocol, since I was having trouble using the hardware SPI, and figured it was easier than fiddling with registers.  I since discovered the breadboard was a bit flaky, and lowering the bit rate would have probably worked too, but that’s for V2.0 :-)  It listens for a number on the serial port, and shifts that number into the 74595’s.  Lather, rinse, repeat.

The other side is an old netbook, running a Processing sketch – since I didn’t write it, and forgot to ask for permission, I can’t attach it, but the essence is a loop that screen-scrapes Twitter’s search API, and sets the bits of a long corresponding to the words that it finds.  I’m now updating it to blink faster or slower based on the frequency that a word occurs, since words like Christmas seem to appear frequently this time of year, who knew?

Rob D

There you have it. For those wondering, the schematic is actually for an upcoming light control shield [Rob] is working on. You can expect to get your own around April. For those that just can’t get enough Alpha One Labs goodness, be sure to join us for their regular UStream this evening at 7pm EST.

Comments

  1. ArduinoFan says:

    No hack.

    One arduino isn’t be enough. You should learn how to use the arduino shield for arduino.

  2. Alpay Kasal says:

    Also worth mentioning, new pics and video to go with it all… http://bit.ly/8R5GPK

    Thanks Robert for the deep followup!

    Alpay

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 93,621 other followers