Cylon Pumpkin

In a fun diversion, I decided the day before a pumpkin carving contest to make a cylon pumpkin. Things got real when I realized I could use the polymorph I had to hold the LEDs in a curve. Here’s an example pic of polymorph in action from an instructable.

polymorph
Polymorph A.K.A Shapelock

And here’s the LED fixture held together with the stuff. I got mine at SparkFunย (I also got the heat gun there).

Shapelock, heat gun and finished eye
Shapelock, heat gun and finished eye
Closeup of "eye"
Closeup of “eye”

I shopped around for a bit looking for something to use for the “lens”. I ended up at an art supply store ordering a strip of translucent grey acrylic. Their computerized saw was down so they couldn’t get it right away, so I was going to go back the next morning.

When I got home I soon had the idea to use a CD jewel case, which is what you see above. It adhered very nicely to the warm polymorph.

The LEDs used are some bar indicators I picked up at Ra-Elco for 20ยข each. There’s actually 2 LEDs in each bar, 4 total in each unit. I only lit one LED per bar, because I got tired of soldering wires. :p

Next I wired it all up and wrote the code (arduino) to control the shift registers. The main loop consists of 2 smaller loops. The first shifts a single 1 down the registers after the single 1 is shifted in. The second loop shifts all 12 bits in with the single 1 bit positioned back one each iteration.

int ndigits = 12;

#define OFF LOW
#define ON HIGH

#define SCLK 2
#define SLATCH 3
#define SOUT 4

// 1 second for full cycle
#define DELAY 1000 / 24

void shift(bool b) {
  digitalWrite(SOUT, b);
  digitalWrite(13, b);
  pulse();
  digitalWrite(SOUT, OFF);
  digitalWrite(13, OFF);
}

void pulse() {
  digitalWrite(SCLK, HIGH);
  //delay(10);
  digitalWrite(SCLK, LOW);
}

void latch() {
  digitalWrite(SLATCH, HIGH);
  //delay(10);
  digitalWrite(SLATCH, LOW);
}

void setup() {
  pinMode(SCLK, OUTPUT);
  pinMode(SLATCH, OUTPUT);
  pinMode(SOUT, OUTPUT);

  digitalWrite(SOUT, OFF);
  digitalWrite(SCLK, LOW);
  digitalWrite(SLATCH, LOW);

  shift(ON);
  latch();

  delay(DELAY*8);

  for (int i = 0; i < ndigits; i++) {
    pulse();
    latch();
    delay(DELAY*8);
  }
}

void loop() {
  int i = 0, j=0;

  // assume already lighted
  // shift lighted position to end
  delay(DELAY);
  for (i = 0; i < ndigits-1; i++) {
    pulse();
    latch();
    delay(DELAY);
  }
  delay(DELAY);
  // Shift backwards
  for (i = ndigits-1; i >= 0; i--) {
    for (j = i; j < ndigits; j++) {
      pulse();
    }
    shift(ON);
    for (j = 0; j < i; j++) {
      pulse();
    }
    latch();
    delay(DELAY);
  }
}

And here it is all wired up! I had to tear apart my sous vide to use my redboard. ๐Ÿ™ Hopefully I’ll have my sous vide PCBs by the time I want to have a controller again. ๐Ÿ˜•

Everything wired up!
Everything wired up!

That nice silvery finish? I superglued a strip of static bag to the front. I only had to glue the ends.

Once I had the pumpkin all carved it was time to shove the eye into the hole. I tried only briefly to fit the whole board inside the pumpkin, the bundle of wires was very stiff and I didn’t want to risk pulling out of the breadboard or breaking the solder joints on the lens side. So I gave up and just left it hanging out the back.

Ready to cut
Ready to cut
Carved and assembled
Carved and assembled

The whole build took approximately 8 or 9 hours. A good chunk of that late into the night with a little dozing. 1 hour looking for the soldering iron. Another hour debugging the code when in fact the problem was my arduino had a fried output pin. CURSES! Soldering 24 wires to DIP leads was of course a time consuming and frustrating portion. The polymorph was easy to work with and I had the eye assembly done in only about 1 hour.

Arduino LiquidCrystal library

RGB backlight, negative display LCD
RGB LCD

As I’ve been progressing on the sous vide controller, I’ve been playing with the LCD 16×2 character display screen that I’m going to put on it. It’s a negative display, RGB backlighted steal of a deal from Amazon.

In this process I got interested in ways to drive the LCD, things like using shift registers and even this amazing Shift1 system to control a whole LCD through a shift register with 1. single. pin. Rather than download various hacked libraries from different sources, I wanted a “standard” library that yet supported all these methods. I wanted support for latching shift registers, registers without latches, and of course shift1, all in the “standard” lib.

So, I did some minor refactoring of the arduino core LiquidCrystal library and extended it with a few more constructor options. You can pass it 3 pins to use a latching shift register where everything goes through the register using just shiftdata, shiftclock, and shiftlatch. You can also pass it a separate enable pin, for 4 pins total, which should speed things up marginally as it doesn’t have to shift the whole register for each LCD enable clock edge up and down. And of course you need that enable pin to use a non-latching register (or a latching register with latch tied to clock), and you can pass 255 as the shiftlatch pin and the library won’t try to use another pin for it.

Then there’s my favorite, the callback function method. You simply define a function that takes three uint8_t types, value, mode, and nbits. The value parameter is the bits the library wants to pound into the LCD, the mode is what it wants the RS pin set to, and nbits is just somewhat of a sanity check, but you can safely ignore it if your function assumes the same nbits that you passed to the constructor. You could write a single function that can do either 4 bit or 8 bit mode, and checks nbits to do either one.

Here’s an example of just how easy it is to use the callback, as well as a link to the github project. If you just use the shift1 library, your custom callback can easily call into the shift1 library to drive your LCD, no need for hacking shift1 directly into the LCD library!