This is post #2 describing the wine storage unit upgrade. See the introduction post for the background.
The first thing that needed figuring out was how to redo the front panel. In the original setup, this is actually where the microcontroller is located, but that wouldn’t work for the redesign because there are only 3 wires connecting the front panel to the power supply on the back. It worked in the original, because the only signal that goes back to the power supply is the PWM output from the microcontroller, everything else is self-contained on the front panel. So there’s only power, ground, and one extra wire going to the front, and since these wires were run before the walls were filled with the insulating foam, it’s basically impossible to run more wires. Well, one wire… sounds like we’ll be using 1-wire!
What functionality needs to go in the front panel?
- Output to the LED display.
- Read the 3 buttons that are used to control the unit.
- The internal “lamp” (a dinky little LED) is fed with a separate circuit going from the front panel to the lamp in the top of the interior, so that power needs to come from here, too.
As you can see, the original only has a 2-digit display which displays the current temperature (or the set point when changed) in Fahrenheit. I thought it would be nice to have a bit more feedback since the functionality will be enhanced significantly. There’s room for a 6-digit display if one cuts out a larger window and moves one of the buttons, so that’s what I went for.
So, how do we control a 6-digit LED display, read 3 buttons, and switch a circuit on and off over one wire? I figured there had to exist some kind of 1-wire controllable switch, and after some searching I came across this application note by Dallas/Maxim: “One-Wire Network Controls Remote SPI Peripherals“. It describes how to control a MAX7221 SPI LED display driver using 3 1-wire switches. Ha, there’s the solution!
Instead of the DS2413 units (each of which has 2 switches) used in the article, I elected to use the DS2408, which is a 8-channel general purpose I/O switch. Each of the 8 channels can be an output, switchable using 1-wire commands, or an input, where you can both read the current state of the input as well as whether the input has changed state since the last time.
So the strategy was to use the one available wire, in addition to +5V and GND, going to the front panel to connect the DS2408. This would then simulate a SPI output as described in the article, talking to the MAX7221 display driver, which can drive the 6-digit LED display. The 3 front panel buttons would be connected to the inputs on the DS2408 so that their state could be read over the 1-wire interface. Finally, the LED lamp would be controlled by a MOSFET that could be turned on/off with another output on the switch. All in all, this would use 3 (for the SPI) + 3 (for the buttons) +1 (for the lamp) = 7 of the 8 channels on the DS2408. Sounds like a go.
There is only room for a roughly 150x20mm circuit board in the front panel, so fitting the display, buttons, 3 pretty large SMD ICs, and wiring up the signals to the display was a bit tricky, but it worked. (I bought a hobbyist license for Eagle CAD a while ago when I realized that I was going to be making circuit boards, so at least I had a good tool.) It was also not exactly cheap, the MAX7221 is ten bucks! (For comparison, the Atmega 328 microcontroller in the Arduinos is less than $5, and that’s a whole computer…) But whatever. Here’s the two sides of the board from Eagle:
And here’s the new board along with the old version. There are some empty spots on the old board since I pillaged the connectors and buttons. (Out of respect for the poor Chinese workers who soldered the board, I’m not showing the solder side of the original board…)
This was the first real board that I etched with the “PCB Fax-in-a-Box” toner transfer set. It worked pretty well, there were only a few places where it had to be patched. As suggested in the instructions to the toner transfer set, I through-plated the vias using a rear window defogger kit (basically seems to be emulsified copper in a carrier that dries). After soldering all the components on, I had a few problems that were related to me forgetting to wire the DS2408 reset pin to a pullup resistor, so it would reset itself randomly. Once that was fixed and the board was prototype-wired to an Arduino, I could reliably communicate with it. If the faster “overdrive” 1-wire timings are used, the throughput is high enough you can drive the display at maybe 20 characters per second even with the quite inefficient 1-wire -> SPI conversion. Plenty fast for what we need.
Next: software. I wrote libraries to control the DS2408 and MAX7221 and added overdrive timings to the OneWIre Arduino library. My newly purchased digital storage oscilloscope came in handy trying to debug the communication and getting the DS2408 protocol right. I haven’t finished implementing the UI since I don’t have the remaining functionality yet, but it’s started. It uses the “State pattern” to implement a state machine controlled by the buttons. It cycles through displaying temperature and humidity, temperature set point is changeable with the buttons, and there’s a programming mode that so far enables changing the display brightness and saving this to EEPROM so it’s persistent. What’s written works nicely, the rest will come once we have a functional unit. The code is in my Arduino repo on bitbucket.
So far, so good. What remains is designing the main controller board with the Atmega328 plus wiring up the cabinet with the sensors. The next post describes the remake of the little lamp inside the cabinet.