Sunday, August 29, 2021

Programmable Timer Using an ATtiny45

I've been wanting to be build a simple timer ever since I got my amateur radio license a few years back.  FCC regulations state that your call sign must be transmitted at the start and end of each transmission and at least once every ten minutes during a call.  My original idea was to use a simple 555 timer to drive a binary counter which would activate an LED upon timeout.  I toyed around with it for a couple of years and had a circuit sketched out but never followed through with it for various reasons.  Fast forward to 2021 when I came across a project someone had created using an ATtiny85 microcontroller.  I'd never heard about these devices before but immediately thought it would be a perfect solution for my timer.

The ATtiny series of chips are 8-bit microcontrollers that fit within an 8-pin DIP footprint.  The ATtiny45 is the one I decided upon using. It has 4096 bytes of flash memory for holding a small program, 256 bytes of EEPROM, 5 useable I/O pins, interrupt capability, etc., etc.  In other words, a very powerful little device contained in a very small package. Another nice feature is its ability to work down to 2.7v.  This allowed me to use a single, 3v coin cell battery as my power source.

Because of its capabilities I decided to expand on my original idea of having a fixed timing function.  The result is a timer that can be programmed from 1 to 255 minutes while driving 2 LEDS.  The countdown function begins when the "timer" button is momentarily pressed.  A green LED then comes on briefly at the top of every minute to indicate countdown activity.  When the elapsed time gets down to 30 seconds the green LED starts flashing on and off.  If, during the countdown period the "timer" button is pushed again, the countdown event starts over.  Otherwise, upon timeout, the red LED comes on.

To set the time, the "timer" button is pushed and held in.  The green LED will then flash on and off representing the number of minutes to countdown for future timing events.  When the button is released, the minute value is then stored in nonvolatile memory (EEPROM) for future reference.

The entire program only occupies 802 bytes of memory.  One other nice feature I included was a clever power on/delayed off circuit I discovered on a YouTube video (Power On Off Shutdown).  It uses a momentary pushbutton, and two MOSFET transistors (along with the ATtiny45).  Push the button once and power is immediately applied to the chip.  Push it again and power is removed after a short delay to allow for processing of any internal housekeeping tasks.  In my case, when I detect a power down request, I flash the red LED twice as an acknowledgement then shut down.

I used EasyEDA software for laying out the circuit board and had the board manufactured by JLCPCB. The board arrived in about a week.  I built the enclosure from pine which I hollowed out to hold and secure the battery.


The "brains" of the timer




Friday, May 21, 2021

Nixie Tube Clock (or Revisiting the 70s)

I built my first digital clock back in the mid 70s.  It was a Heathkit of course (one of many I built as a teen) and it had a cool looking Nixie-like display.  Fast forward to today when I recently came across a YouTube video featuring a clock with real Nixie tubes.  Most of the tubes available today were manufactured back in the 70s and 80s for instrumentation, test equipment, etc. but apparently there has been a revival of these devices for digital clocks in particular so I thought why not go for it.  The first challenge was locating the tubes but that actually proved easier than I thought thanks to eBay.  I found four tubes from a Russian seller (type IN-8) which were labeled as NOS (new old stock) for $75.00.  These are high voltage devices (upwards of 170VDC or more needed for activating the internals).   To avoid having to scratch build a supply, I decided to purchase one (again from eBay).  A detailed description of the boost converter kit I bought can be found at Threeneuron's Pile o'Poo.  Below is the finished board:

Pretty nifty little device and it only takes up a bit more than one square inch of space.

Next came the components needed to control the clock functions and drive the displays.  I chose an ESP8266 based WiFi module for the controller (ESP8266DevKitC-02D).  The controller periodically retrieves the time from an NTP server, then converts it into four bytes (32 bits) and outputs it via an SPI interface to a serial to parallel logic converter (HV5530).  This particular converter has 32 channels, each capable of handling up to 300V, so it worked perfectly for my application.  

To the right is the controller and voltage regulator along with the various wiring harnesses needed to connect with the display circuit board.  The blue section to the right of the controller is the WiFi antenna.

One minor issue cropped up when using this particular controller and driver and that involved their respective supply voltages.  The ESP8266 is a 3.3v device while the HV5530 uses 12v.  Therefore, to connect the two a level shifter is required.  This was easily solved by using an N-channel MOSFET and two pullup resistors for each control line (shown below):

Level shifter

One issue that all Nixie tubes have in common is something called "cathode poisoning".  As the individual digits (cathodes) are turned on, they emit microscopic particles which can coat the unlit elements.  Over time, enough material can coat the other cathodes to the point that they start to go dim.  To reduce this effect, an anti-poisoning routine is needed in software.  By turning on each digit in rapid succession over a given period of time, the poisoning process can be minimized.  So, prior to turning the tubes off for good each night, I run my routine for sixty seconds, then shut down (I decided to turn off the tubes at 11:00p to help lengthen their useful life which is stated to be in the neighborhood of 10,000 hours.  I have read, however, that the posted numbers for these tubes is very much on the conservative side but why take any chances?).

A circuit with this many components required a custom printed circuit board so instead of rolling my own,  I used EasyEDA software to create the schematic and then layout the components.  The gerber/drill files generated by the software were then emailed to JLCPCB, a PCB fab house in HongKong.  I received my board in less than 2 weeks (actually, the minimum number of boards that can be ordered is five but total cost including shipping was only $15.00 so no complaints from me).  Here is an image of an early board created by the PCB software after I made an initial component placement:

Early PC board prototype

For comparison, here is the actual board I received from the fab house along with a few components I soldered on:

Bottom view - partially populated PC board

A couple of minor changes noted between the blue and green board images are due to updates I made to the schematic later on.  I decided to add a neon tube between the hour and minute Nixie tubes to act as a colon and I also realized I didn't need one of the voltage level shifters after all.  For what its worth, the 44-pin chip was a real bear to solder in.  Not my best soldering job but it works.  The finished board is seen below (I left off one tube to show the backlight LED found under each tube:

Top view - showing a backlight LED
To wrap things up I decided to make my own enclosure and chose maple and walnut because I thought  the contrasting colors would look nice.  All pieces came from 1/4" stock.

I used double sided carpet tape to attach the top piece and screws for the bottom piece.  A clear finish of linseed oil was then applied to protect and beautify the wood.

Time (designated by colon off)

Date (designated by colon on)

Display elements highlighting differences in depth

Rear view



Update (Sep 2023)
Currently, the display is only on between the hours of 8:00a and 11:00p to prolong tube life.  This is true regardless of whether the room its located in is occupied or not.  I decided to go one step further in my quest to improve tube longevity by adding a light sensor.  This was easily achieved by adding a photo detector and resistor combination connected to the controller's ADC input.  A low light condition results in a low voltage reading (ie. counts) on the analog input while a high light condition results in a high voltage reading.  Now, whenever the room light is turned off (indicating the absence of a person) the display will also turn off.  Conversely, when someone enters the room and turns on the light the display will turn on.

Tuesday, March 16, 2021

Bird Cam

One of my wife's hobbies is watching and sketching birds.  We even installed a bird feeder outside of our bedroom window so that she could periodically look for any bird activity.  I eventually realized that she could accomplish the same thing if we had a camera trained on the feeder and then watch the live stream on her iPad.  I had been reading about the ESP32-Cam modules lately and thought this might be a good opportunity (ie. excuse) to build something for her.

To power the unit I used a 6v solar panel I happened to have lying around and hooked that to a solar powered battery charger (Lipo charger).  The charger connects to two parallel configured 3.7v Lipo batteries which in turn provide the input voltage needed to drive a 3.3v LDO voltage regulator.  A simplified schematic is shown below:


I used an onboard ADC channel to continually monitor the battery voltage.  Since the maximum allowed ADC input level of an ESP32 is 3.3v and the maximum expected battery voltage is 4.2v, I had to add a simple voltage divider to scale down the voltage level.   When or if the battery voltage ever drops below a preset level (3.7v in this case), the unit will shut down to conserve power.  In shut down mode (actually called "deep sleep mode"), the module draws ~4mA whereas when fully active the current draw can exceed 250mA.  After a specified number of hours the unit will "wake up", hopefully under conditions suitable for battery charging.  The electronics along with both batteries are installed in a waterproof enclosure with a clear cover (shown on the right minus the cover).

The location of the feeder I'm using this camera with is quite a distance from our router, so I'm having some issues right now with signal strength.  Therefore, I will probably be adding an external WiFi antenna in the near future to boost signal levels.

Here is a recent visitor enjoying a snack:










Update (June 2021)
Two changes were incorporated:

1) After putting up with slow and intermittent browser response times I finally decided to add the aforementioned external antenna.  This seems to have done the trick and browser interaction is now much more robust.

2) The Lipo battery power system I was using was not able to reliably supply the camera module with enough power to operate.  We get a lot of cloudy and rainy weather during parts of the year and when that occurs the batteries never seem to reach a fully charged state.  Couple that with the high current demands of the camera and well, things just kept shutting down.  I solved this by replacing the batteries and charging system with a 5v wall unit.  This eliminated the unit's portability (unfortunately) but definitely improved its reliability.