Tiny Machine Learning On The Attiny85

We tend to think that the lowest point of entry for machine learning  (ML) is on a Raspberry Pi, which it definitely is not. [EloquentArduino] has been pushing the limits to the low end of the scale, and managed to get a basic classification model running on the ATtiny85.

Using his experience of running ML models on an old Arduino Nano, he had created a generator that can export C code from a scikit-learn. He tried using this generator to compile a support-vector colour classifier for the ATtiny85, but ran into a problem with the Arduino ATtiny85 compiler not supporting a variadic function used by the generator. Fortunately he had already experimented with an alternative approach that uses a non-variadic function, so he was able to dust that off and get it working. The classifier accepts inputs from an RGB sensor to identify a set of objects by colour. The model ended up easily fitting into the capabilities of the diminutive ATtiny85, using only 41% of the available flash and 4% of the available ram.

It’s important to note what [EloquentArduino] isn’t doing here: running an artificial neural network. They’re just too inefficient in terms of memory and computation time to fit on an ATtiny. But neural nets aren’t the only game in town, and if your task is classifying something based on a few inputs, like reading a gesture from accelerometer data, or naming a color from a color sensor, the approach here will serve you well. We wonder if this wouldn’t be a good solution to the pesky problem of identifying bats by their calls.

We really like how approachable machine learning has become and if you’re keen to give ML a go, have a look at the rest of the EloquentArduino blog, it’s a small goldmine.

We’re getting more and more machine learning related hacks, like basic ML on an Arduino Uno, and Lego sortings using ML on a Raspberry Pi.

Get Twelve Charlieplexed PWM Outputs From An ATtiny85

Most of us are aware that charlieplexing can drive a large number of LEDs from a relatively small number of I/O pins, but [David Johnson-Davies] demonstrates adding another dimension to that method to create individually controlled PWM outputs as well. His ATtiny85 has twelve LEDs, each with individually-set brightness levels, and uses only four of the five I/O pins on the device.

Each LED can be assigned a brightness between 0 (fully off) and 63 (fully on). The PWM is done by using one of the timers in the ATtiny85 to generate a periodic interrupt, and the ISR for the interrupt takes care of setting the necessary ratios of on and off times for each charlieplexed output. The result? Twelve flicker-free LEDs with individually addressable brightness levels, using an 8-pin microcontroller and just a few passive components on a tiny breadboard. There’s even one I/O pin left on the ATtiny85, for accepting commands or reading a sensor.

[David] really wrings a lot out of the ATtiny series of microcontrollers with his compact projects, like his Tiny Function Generator (which recently got an update.) He also demonstrated that while charlieplexing is usually used with LEDs, charlieplexing can be used with switches just as easily.

Drawing On An OLED With An ATtiny85, No RAM Buffers Allowed

Small I2C OLED displays are common nowadays, and thanks to the work of helpful developers, there are also a variety of graphics libraries for using them. Most of them work by using a RAM buffer, which means that anything one wants to draw gets written to a buffer representing the screen, and the contents of that buffer are copied out to the display whenever it is updated. The drawback is that for some microcontrollers, there simply isn’t enough RAM for this approach to work. For example, a 128×64 monochrome OLED requires a 1024 byte buffer, but that’s bad news if a microcontroller has only 512 bytes of RAM in total like the ATtiny85. [David Johnson-Davies] has two solutions: a Tiny Graphics Library that needs no RAM buffer and an even slimmer Tiny Function Plotter, which we’ll discuss in order.

Tiny Function Plotter works on both SSD1306 and SH1106-based displays.

[David]’s Tiny Graphics Library works by taking advantage of a feature of SH1106 driver-based displays: the ability to read the display over I2C as well as write to it. With the ability to perform read-modify-write on a section at a time, using a large RAM buffer can be avoided. The only catch is that the library only works with OLEDs using the SH1106, but the good news is that these are very common at the usual Chinese resellers. ([David] notes that SH1106 is sometimes misspelled as “SSH1106”, so keep that in mind when searching.)

What about all those other SSD1306-based OLED displays out there? Are they out of luck? Not quite. [David] has one more trick up his sleeve: his Tiny Function Plotter works on the SSD1306 and also requires no RAM buffer. It’s unable to write text, but it can easily handle drawing graphs plotting things like values over time while needing very little overhead.

Another approach we’ve seen for using OLEDs driven by microcontrollers with limited memory is the solution [Michael] used in Tiny Sideways Tetris, which was done in part by realizing the smallest screen element he needed was a 4×4 block, and using that premise as the basis of a simple compression scheme.

I2C Bootloader For ATtiny85 Lets Other Micros Push Firmware Updates

There are a few different ways of getting firmware onto one of AVR’s ATtiny85 microcontrollers, including bootloaders that allow for firmware to be updated without the need to plug the chip into a programmer. However, [casanovg] wasn’t satisfied with those so he sent us a tip letting us know he wrote an I2C bootloader for the ATtiny85 called Timonel. It takes into account a few particulars of the part, such as the fact that it lacks a protected memory area where a bootloader would normally reside, and it doesn’t have a native I2C interface, only the USI (Universal Serial Interface). He’s just released the first functional version for the ATtiny85, but there’s no reason it couldn’t be made to work with the ATtiny45 and ATtiny25 as well.

Timonel is designed for systems where there is a more powerful microcontroller or microprocessor running the show (such as an ESP8266, Arduino, or even a board like a Raspberry Pi.) In designs where the ATtinys are on an I2C bus performing peripheral functions such as running sensors, Timonel allows the firmware for these peripheral MCUs to be updated directly from the I2C bus master. Embedded below is a video demo of [casanovg] sending simple serial commands, showing a successful firmware update of an AVR ATtiny85 over I2C.

Continue reading “I2C Bootloader For ATtiny85 Lets Other Micros Push Firmware Updates”

Custom ATTiny85 Board Powers Kids’ Light Show

We’ve often said that kids with hackers and makers for parents must be some of the luckiest kids in the world. While all the other children have to settle for some mass produced drivel from Toys“R”Us Amazon, they’ve got some of the most thoughtfully engineered and built toys and gadgets on the planet. After all, there’s no way any hacker worth their salt is going to give anything less than 110% for their own child.

A case in point is this RGB star nightlight that [Unexpected Maker] built for his children. The star itself is simple enough, just a basic shape printed in transparent PLA on his Prusa i3. The impressive part is how he lights it up. Rather than stick an Arduino or ESP8266 in there as we have seen plenty of times before, he’s put together his own custom ATTiny85 board specifically for controlling the RGB LED strips.

The board, which he calls TinyDev, is designed to be the same thickness as NeoPixel style LED strips so it can fit inside tight spaces. He solders it onto the tail end of his LED strip, adds a photoresistor so the star can tell when it’s time to light up, and then snakes the whole arrangement through a channel printed in the star itself. There’s a battery pack in the middle, but that’s about it. It really does allow for a remarkably clean LED strip implementation, and the mind can’t help but start thinking of interesting possibilities when you can tuck the controller into the same space as the lights themselves.

[Unexpected Maker] has made the TinyDev completely open source for anyone who wants to build their own, but it’s also available on Tindie if you want to get one to play with quickly. If you’re looking to light up the little one’s room with somewhat more mainstream methods, we’ve got that covered too.

Continue reading “Custom ATTiny85 Board Powers Kids’ Light Show”

Tiny Function Generator On The ATtiny85, Complete With OLED

It’s easy to have a soft spot for “mini” yet perfectly functional versions of electronic workbench tools, like [David Johnson-Davies]’s Tiny Function Generator which uses an ATtiny85 to generate different waveforms at up to 5 kHz. It’s complete with a small OLED display to show the waveform and frequency selected. One of the reasons projects like this are great is not only because they tend to show off some software, but because they are great examples of the kind of fantastic possibilities that are open to anyone who wants to develop an idea. For example, it wasn’t all that long ago that OLEDs were exotic beasts. Today, they’re available off the shelf with simple interfaces and sample code.

The Tiny Function Generator uses a method called DDS (Direct Digital Synthesis) on an ATtiny85 microcontroller, which [David] wrote up in an earlier post of his about waveform generation on an ATtiny85. With a few extra components like a rotary encoder and OLED display, the Tiny Function Generator fits on a small breadboard. He goes into detail regarding the waveform generation as well as making big text on the small OLED and reading the rotary encoder reliably. His schematic and source code are both available from his site.

Small but functional microcontroller-based electronic equipment are nifty projects, and other examples include the xprotolab and the AVR-based Transistor Tester (which as a project has evolved into a general purpose part identifier.)

Continuity Tester Uses The ATtiny85’s Comparator

There’s an inside joke among cyclists – the number of bikes you need is “n+1”, where “n” is your current number of bikes. The same probably also applies to the number of tools and equipment a hacker needs on their workbench. Enough is never enough. Although [David Johnson-Davies] has a couple of multimeters lying around, he still felt the urge to build a stand-alone continuity tester and has posted details for a super-simple ATtiny85 based Continuity Tester on his blog. For a device this simple, he set himself some tall design goals. Using the ATtiny85 and a few SMD discretes, he built a handy tester that met all of his requirements and then some.

The ATtiny85’s Analog Comparator function is perfectly suited for such a tester. One input of the comparator is biased such that there is a 51 ohm resistor between the input and ground. The output of the comparator toggles when the resistance between the other input and ground is either higher or lower than 51 ohms. Enabling internal pullup resistors in the ATtiny85 not only takes care of proper biasing of the comparator pins, but also helps reduce current consumption when the ATtiny85 is put to sleep. The test current is limited to 100 μA, making the tester suitable for use in sensitive electronics. And enabling the sleep function after 60 seconds of inactivity reduces standby current to just about 1 μA, so there is no need for a power switch. [David] reckons the CR927 button cell ought to last pretty long.

For those interested in building this handy tester, [David] has shared the Eagle CAD files as well as the ATtiny85 code on his Github repository or you could just order out some boards from OSHpark.