Bike Wheel Light Flashes Just Right

When it comes to safely riding a bike around cars, the more lights, the better. Ideally, these lights would come on by themselves, so you don’t have to remember to turn them on and off every time. That’s exactly the idea behind [Jeremy Cook]’s latest build — it’s an automatic bike light that detects vibration and lights up some LEDs in response.

The build is pretty simple — a coin cell-powered ATtiny85 reads input from a spring vibration sensor and flashes the LEDs. This is meant to complement [Jeremy]’s primary bike light, which is manually operated and always on. We especially like that form follows function here — the board shape is designed to be zip-tied to the spokes so it’s as close to the action as possible. He cleverly used cardboard and a laser cutter to mock up a prototype for a board that fits between the spokes. Pretty cool for your second professionally-fabbed PCB ever, if you ask us. Ride past the break to check out the build video.

If you don’t think fireflies on your spokes are enough to keep you safe, go full rainbow party bike.

Continue reading “Bike Wheel Light Flashes Just Right”

Old Gas Meter Gets Smart With The ESP8266

Measuring the usage of domestic utilities such as water, gas or electricity usually boils down to measuring a repetitive pulse signal with respect to time. To make things easy, most modern utility meters have a pulsed LED output, which can be used to monitor the consumption by using an external optical sensor. But what do you do if your meter isn’t so cooperative?

That’s exactly what [Francesco] had to figure out while developing the non-invasive gas tracking system he calls ESPmeter. His meter might not have an LED, but it did have a magnet attached to the counter disk which activated an internal hall sensor. With some hacking, he was able to attach an external Hall-effect sensor to pick up this magnet and use the signal to monitor his daily gas consumption.


A big stumbling block in such projects is the issue of powering the device for an extended period, and remembering when it’s time to change the batteries. With the clever use of commonly available parts, he was able to reduce power consumption allowing three AA batteries to last about a year between changes. For one thing, he uses an ATtiny13 to actually read the sensor values. The chip doesn’t run continuously, its watchdog is set at 1 Hz, ensuring that the device is woken up often enough so that it has time to power up the sensor and detect the presence of the magnet. Battery voltage is also measured via a voltage divider connected to the chip’s ADC pin.

At regular intervals throughout the day, the ESP8266 polls the ATtiny13 to pull the stored sensor pulses and voltage measurement. Then at midnight, the ESP transmits all the collected data to a remote server. Overall, this whole scheme allows [Francesco] to reliably gather his gas consumption data while not having to worry about batteries until he gets the low voltage notification. Since the data visualization requirements are pretty basic, he is keeping things simple by using Plotly to display his time series data.

If you are unfortunate enough to have an even older meter which doesn’t use optical or magnetic rotation sensing, you can use a disassembled mouse to keep track of the Gas Meter.

AVR Microcontroller Doubles Up As A Switching Regulator

[SM6VFZ] designed, built and tested a switched-mode DC-DC boost regulator using the core independent peripherals (CIP) of an ATtiny214 micro-controller as a proof of concept, and it looks pretty promising!

A Buck, Boost, or Buck-Boost switching regulator topology usually consists of a diode, a switching element (MOSFET) and an energy storage device (inductor/capacitor) in the power path, and a controller that can measure the output voltage, control the switching element and add safety features such as current limiting and temperature shutdown. A search for switching regulators or controllers throws up thousands of parts, and it’s possible to select one specifically well suited for any desired application. Even so, the ability to use the micro-controller itself as the regulator can have several use cases. Such an implementation allows for a software configurable switch-mode regulator and easy topology changes (boost, buck, fly back etc.).

The “Getting Started with Core Independent Peripherals on AVR®” application note is a good place to get an overview of how the CIP functionality works. Configurable Custom Logic (CCL) is among one of the powerful CIP peripherals. Think of CCL as a rudimentary CPLD — a programmable logic peripheral, which can be connected to a wide range of internal and external inputs such as device pins, events, or other internal peripherals. The CCL can serve as “glue logic” between the device peripherals and external devices. The CCL peripheral offers two LookUp Tables (LUT). Each LUT consists of three inputs, a truth table, a synchronizer, a filter, and an edge detector. Each LUT can generate an output as a user programmable logic expression with three inputs and any device that have CCL peripherals will have a minimum of two LUTs available.

This napkinCAD sketch shows how [SM6VFZ] implemented the boost regulator in the ATtiny214. The AND gate is formed using one of the CCL LUT’s. The first “timer 1” on the left, connected to one input of the AND gate, is free running and set at 33 kHz. The analog comparator compares the boosted output voltage against an internally generated reference voltage derived from the DAC. The output of the comparator then “gates” timer 1 signal to trigger the second “timer 2” — which is a mono-shot timer set to max out at 15 us. This makes sure there is enough time left for the inductor to completely release its energy before the next cycle starts. You can check out the code that [SM6VFZ] used to built this prototype, and his generous amounts of commenting makes it easy to figure out how it works.

Based on this design, the prototype that he built delivers 12 V at about 200 mA with an 85% efficiency, which compares pretty well against regular switching regulators. Keep in mind that this is more of a proof-of-concept (that actually works), and there is a lot of scope for improvement in terms of noise, efficiency and other parameters, so everyone’s comments are welcome.

In an earlier blog post, we looked at how ATmegas with Programmable Logic came about with this feature that is usually found in PIC micro-controllers, thanks to Microchip’s acquisition of Atmel a few years back. But we haven’t seen any practical example of the CCL peripheral in an Atmel chip up until now.

Improve ATtiny Timing Accuracy With This Clock Calibrator

The smaller ATtiny microcontrollers have a limited number of pins, and therefore rely on an internal 9.6 MHz oscillator rather than an external crystal. This oscillator lacks the accuracy of a crystal so individual chips can vary over a significant tolerance from the nominal figure. Happily the resulting timing inaccuracies can be mitigated through a calibration process, and [Stefan Wagner] has incorporated this into his Tiny Calibrator. In addition, it also has the required charge pump circuitry to reset the internal fuses to rescue “bricked” ATtinys, thus allowing those little mistakes to be salvaged.

The board has its own larger ATtiny with a crystal oscillator and an OLED screen, allowing it to measure that of the test ATtiny and generate a correction factor which it applies to the chip. This process is repeated until there is the smallest possible difference from the standard. You can find the files for the hardware on EasyEDA, and the software in a GitHub repository.

It’s important to state that the result will never be as stable as a crystal so you’d be well advised not to put too much trust in those timers, but at least they won’t be as far off the mark as when shipped. All in all this is a handy board to have at hand should you be developing for the smaller ATtiny chips.

Be careful when chasing clock accuracy — it can lead you down a rabbit hole.

TinyTacho: Rotational Speed Measurement Without The Bulk

An electronic tachometer is a straightforward enough device, in which the light reflections from a white spot on a rotating object are detected and counted over time, measuring the revolutions per minute (RPM). It’s a technique that has its roots in analogue electronics where the resulting pulses would have fed a charge pump, and it’s a task well suited to a microcontroller that simply counts them. But do you need an all-singing, all-dancing chip to do the job? [Stefan Wagner] has done it with a humble ATtiny13.

His TinyTacho is a small PCB with an IR LED and photodiode on one end, a small OLED display on its front, and a coin cell holder on its rear. The electronics may be extremely simple, but there’s still quite some effort to get it within the ATtiny’s meagre resources. Counting the revolutions is easy enough, but the chip has no I2C interface of its own and some bitbanging code is required. You can find all the design files and software you need in a GitHub repository, and he’s put up a video of the device in action that you can see below the break.

Tachometers are a popular project hereabouts, and we’ve featured a lot of them over the years. Perhaps the best place to direct readers then is not to another project, but to how to use a tachometer.

Continue reading “TinyTacho: Rotational Speed Measurement Without The Bulk”

The Mystery Of A Particular ATtiny85 Fuse

First-timers playing with 8-bit micros such as the AVR and PIC will at some point in their lives, find themselves locked out of their MCUs. This is usually attributed to badly configured fuses that disable certain IO functions rending the device unprogrammable via conventional ICSP methods. [Uri Shaked] shares his story of how his ATtiny85 got locked and became the subject of a lengthy investigation into fuse bit configurations.

[Uri]’s journey started when he accidentally left some pins of the device connected to a second board while he was flashing the firmware. He quickly researched online for a solution for the problem and it turns out, there are a number of recipes to resolve the issue. As it turns out, his problem was not so straight-forward and warranted more digging. [Uri] ended setting up a High Voltage Programming serial programming setup and then probing the communications. He discovered that the chip refused to reset its fuses and would reject attempts to set fuses.

Further investigation of the fuse bits and reading them proved useful in understanding that the memory protection features were preventing alteration of the device. The quick-fix was to erase the ATtiny and things were back to normal thereafter. [Uri] details his pursuit of reading and comparing fuse bits from the impacted chip against a fresh device which is where he makes the discovery. The write-up is a case study in the investigation into the idiosyncrasies of device programming and will be a great resource for many and reduce hair loss for some.

Once you get your hands on an ATTINY, there are a number of small experiments to be done to cure boredom. Be sure to share your experiments and stories with us to inspire the masses.

Minimal TinyAVR 0 Programming

When [Alain] wanted to use some of the new TinyAVR 0 chips — specifically, the Attiny406 — it seemed overkill to use the Windows IDE. There are plenty of sources of information on programming other AVR chips using simple command line tools, but not for these newer 0-series parts which use a new programming protocol known as UPDI. That led to a deep diving into how to program a TinyAVR 0 with a text editor, makefile, and USB-to-serial cable.

The Attiny406 has 4K of flash, 256 bytes of RAM and can run at 20 MHz with no external clock. You might think programming would be similar to a regular AVR part, but these tiny devices use UPDI (Unified Programming and Debug Interface) which uses 3 pins for programming. Older devices used different protocols.

It is very easy to create a UPDI programmer. A USB to logic-level serial cable and a 4.7K resistor is all it takes. There’s Python code that knows how to drive the protocol, too. You can also use the logic-level serial port on the Raspberry Pi with some device tree modifications explained in the code’s documentation.

[Alain] made a nice breakout board for the device. It fits a breadboard, allows for 5V or 3.3V operation, and has an LED and switch. Nothing fancy, but handy. Once you know how to ship a hex file to the chip, the rest is pretty standard. While the AVR version of gcc doesn’t cross-compile for the ATTiny out of the box, there is a device pack from Microchip that enables that feature.

The trend is to go to bigger processors, not smaller, but when you need to cram something in a small space, save a few pennies per unit, or draw very little power, these tiny processors can be just the ticket. The processors may be small, but if you work you can do some pretty big things with them.