attiny85 powered kWh-meter-meter and 1-wire host

At Revelation Space we wanted some insight into our powerusage. After a few prototypes on arduino’s I ended up building a small board powered by an attiny85.

In later revisions I added a Dallas/Maxim 1-Wire bus that will read out DS18B20 temperature sensors, so I could monitor the temperature of the server that was logging the data (it didn’t have any supported sensors).

The schema shows the attiny85, the programming header (non-standard pinout ISP header) and used parts.

The LED will blink for every received pulse, so you can verify this with the original meter. I made the connection to the LDR as a 2-pin jumper-block, so I could easily disconnect the LDR, which is connected to a long cable so it can reach the led on the kWh-meter.

JP1 on the schema is the 1-Wire bus. I ended up using just the 2-pin version. On my board I terminated this on a 8×2 pin female header.

The final board:

The kWh-meter I am monitoring blinks a led a number of times per kW used. In this case it blinks 1000 times per kW, but I have seen other meters that blink 400, 480, 600 and 1000 times. This is usually documented somewhere on the meter itself.

It looks somewhat like this one:

The trick is to attach an LDR in front of the LED on the meter, and then read out the data using an analog port on the attiny. Make sure to blank out any outside light that can hit the LDR using black tape.

The code for the attiny can be found on my Github

The last components are rrdtool to make graphs and a perl script to log data from the (serial) attiny and pipe the data to rrdtool. Rrdtool and perl code can also be found on github.

After a few days of logging you should have a good insight into your power usage:

If your kWh-Meter uses a rotating disc, Juerd has a nice design that works with those meters. It’s based on an arduino and uses 7-segment displays to give a live insight into the used wattage.

USB-ASP Avr programmer from e-Bay, issues with attiny85

I recently bought a USBASP programmer from e-Bay, the one pictured here

It seemed to work just fine when I was programming attiny4313’s or atmega’s, but would fail on verification when programming attiny85’s (and probably other small/slow attiny’s).

Setting the fuses would work, but writing flash would fail consistently.

The trick to resolve this was to update the firmware to the 2011 version of USBASP, which can be found at http://www.fischl.de/usbasp/.

To program the USBASP itself, you need a second programmer (I used a usbtiny) and you need to jumper J2 (which are the 2 solderpoints next to the leds).

After upgrading the firmware, use avrdude with the ‘-B 10‘ option to write to slow devices. This option is not needed with faster (1.5Mhz and up) devices.