RC Networks, They Matter!

After a long hiatus, I’m finally dusting off some projects and getting back into them, well, one in particular, the sous vide controller. I knew there were board errors from the prints I ordered early last year, I had even started to fix some of them. I got the boards and components and eagerly assembled one. Once I powered it on, there was one immediate problem. The LCD contrast with a diode that I wrote about previously, well, it’s not giving so constant a contrast on this board. Maybe it’s a poor diode, maybe I’ll build a bench power supply to vary the voltage across different diodes and see how they respond.

After putting some code on the chip, I found another problem. The push button on the encoder would not work. I got nothing at all from it. From probing the board and the resistors, I discovered that the button was active high, but my idle resistors were also pull-up. Tsk tsk. Ah well, that’s an “easy” fix, just scratch out some traces, re-route (in this case a power rail) around them, no problem, and connect the common side of those resistors to GND instead.

That got the button working, but not the encoder. Long story short, I played with the hard-to-see LCD for a while and then set it down for many moons. Oh that’s right, I also had to cut the common freewheel diode leg from the transistor array because apparently that’s not supposed to connect to “common”. Oops.

Fast forward, and now I dust it off, scratch my head, and try writing some simple encoder and button tests onto it. When they failed, I turned to my schematics, and scratched my head again. What I noticed actually pretty quickly is that the encoder legs were active LOW, but the push button active HIGH! *sigh* “I see why I did that,” in a way at least. I had to tie the push button active high because it shared with the common anode on the encoder LEDs. And it would seem I found that out after I made the quadrature active low.

So, I fixed all of that. I’m determined now to get this board to work. Of course I’ll make another run with corrections, but only after I find all the corrections. A few more trace cuts, more jumpers, and I got all the inputs working. Well, kinda… The rotary worked, a little bit. But not nearly fast enough. First I sped up the polling and that helped, only a little. Then I went full on PCINT driven, and no more improvement was to be found. At this point  I was beginning to suspect the RC network was too slow.

debounce-old

I plugged those values into units (not that that would be particularly needed in this case, but just the same, I highly recommend units!) and looky there. Fall time of 15ms! Yikes.

So I replaced the capacitors with some 15pF I found at Ra-Elco, and now it works flawlessly.

Moral is, don’t make board mistakes.
Moral is, you’re probably going to make board mistakes.
Moral is, don’t just pick component values because … whatever? Ya, don’t do that.

LCD Contrast With a Diode

Some very long time ago I read something about using a diode forward voltage to feed v0 for LCD contrast. I tried it forthwith, and indeed it worked for me, too! Now it may well be that not all LCD look great at 0.65V on v0. YMMV

I believe I have found where I read that, if memory serves, at good ol’ Ray’s Hobby. Also known (by me at least) for the AASaver.

Speaking of AASaver, I fried mine. 🙁 Time to get a new one, and perhaps a part or two to fix the other one.

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.

Broken, Now Fixed

Seems this blog was broken, not sure for how long. Tracked the issue to a missing AllowOverides directive for apache.

Hey googlers. If you have a wordpress site and you get 404 on every page but the main page, and you’ve checked everything else everyone tells you to do (check the .htaccess file, check mod_rewrite is on, save the permalink style again and again) and still no dice? Check apache’s AllowOverrides for the directory. 😀

h/t http://www.electrobucket.com/linux/debug-wordpress-permalinks-not-working

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!

More Boxy and USBee

Had some more fun with Boxy and my USBee analyzer. I’ve found a decent online supplier of aluminum at onlinemetals.com. (Now if only I could find one that takes bitcoin?) I got some 2″x1″ channel cut to 4″ long. The top of the electrical box is 2″x4″ and it fits nicely. I also got a lot of sizes and shapes of aluminum pieces, in part to justify the shipping expense, but also to experiment with other enclosures. I tested the channel on the target hotplate and it worked rather well, the surface of Boxy only got up to 35C. So this is nice because I can make the lid out of aluminum without scrounging up random pieces from my local electronics supply store. The aluminum lid is good because I can mount the triac and circuit board standoffs directly to the lid. Everything is flush and the triac enjoys a good thermal connection to the outside of the box. The flanges on the channel also make a decent enough heatsink, so I don’t have to add a separate heatsink and another thermal junction to the equation.Boxy powering an Aroma hotplate

I may need a better hotplate, however. This Aroma model I have got down to about a 65% duty cycle and the water wasn’t getting much hotter than 75C. This is hot enough for most sous vide recipes, but the spring controlled duty cycle ramping down to 2/3 will probably wreak havoc on the PD controller. 🙁 I’m thinking about giving the knob a setting, or adding a switch, that puts it at 100% always on. This worries me, though, for the housing of the hotplate was already getting above 100C, and the counter beneath got up to 60C.

Various pieces of extruded aluminum

Here I have the PulseView output of the zero-cross detect circuit in the boxy. The pulse width is about 900 microseconds, and the time from pulse leading edge to pulse leading edge was 8.3 milliseconds, which is close enough to 120Hz to chalk that up to eyeballing the measurement tickmarks error. PulseView has no ruler function, least of not all an automatic edge to edge time difference display. Oh well.

This is about 10% pulse on time. Assuming the pulse center is exact zero, that’s 5% cycle lead time, but cycle here is of course 180 degrees. sin(pi*0.05) = 0.15, so sampling at a rate where you would hit the worst case you would turn on the triac when the voltage is still at 15%. Of course you can over sample and count toward the middle of the pulse before switching. Just thought I’d throw that in there.

zcd1zcd2zcd3

USBee and PulseView

If you get one of these USBee AX PRO logic analyzers and you try to use it in linux with pulseview you’ll probably get the cryptic error “Failed to set time-based sample limit.”

USBee clone
USBee clone

What actually fails is uploading the firmware to the device, which the pulseview message kindly leaves out. If instead you use sigrok-cli you might notice that the firmware failed. The problem is one of mere permissions. You can simply run pulseview as root and it works dandy. Or, if you followed the instructions here and copied the udev rules to /etc/udev/rules.d then you just need to add your user to the group plugdev. If you use RPM you can see where the rules file is in the libsigrok package. It’s in /usr/share/udev/rules.d/. Actually, I’m not sure if it even needs to be copied from there to /etc to work. It may work just fine where it is.

Now, enjoy using your logic analyzer in linux!

Introducing Boxy

Watch this video on YouTube.

Here’s the up-to 15 amp wall socket switch I’ve been working on, dubbed “boxy”. With a big enough heatsink you can use it for 15 amps and with no heat sink 5 amps may be too much. My primary use for this contraption is going to be for “sous vide”, a cooking method based on tightly controlled temperature. And for this the boxy will be switching a 1100 watt countertop hotplate, and that means about 10 amps. I’ll need a heatsink, but a moderate sized one should do.

Note that only the 2 yellow jumper wires closest to the battery are doing anything (and this demonstration would have worked with only one of those). All the other wires are just left overs from previous tinkers.

Now for the features of the boxy:

  • Completely isolated (from mains voltage) control circuitry accessed through 4 wires exiting the boxy
  • internal (and also isolated) zero cross detector – pulses every zero cross (120Hz for home sockets in the US)
  • simple control on one pin, drive it high to switch on, drive low to switch off
  • common ground for the zero cross

In the video I have the control wires exposed by a regular 4-wire phone cable and connector, though you could use whatever 4 pin connecter is most convenient for you (like a TRRS, RJ45, screw terminals, molex, etc)

Made from:

  • 1x Steel handy/utility box, $0.91 at Lowes
  • 1x 1 ft extension cord (sometimes called “Power Strip Savers”) cut in half, $8.50/5 on amazon
  • 2x NM cable connector (plastic: 20 cents each in a 10 pack, adjustible steel: $0.40 each)
  • 1x Cover for the steel box (in the video I have an aluminum plate which helps for heat dissipation, I have no source for these, though you could cut/fab your own), Lowes has a cover with a punch out hole (useful for the heatsink) for $0.98
  • 1x heatsink, necessary for any appreciable currents (lights would be fine without)
  • PCB and electronic components (to be included with the build instructions) ~$5-$10?

When I post the build instructions I’ll have a tighter cost estimate (and probably even kits for sale), but I think this could be built for under $20 apiece. Stay tuned for the build post!