Close

Programming the receiver

A project log for Snail Mail Notifier

Low power, wireless device that informs user of regular mail.

SolenoidSolenoid 01/20/2016 at 07:210 Comments

The receiver is a blatant copy of a Digispark with a format that suits this project, therefore it can be programmed the same way.

The latest library version has a required fix for this project, but it don't seem to be working very well with Arduino IDE, so follow the official Digispark tutorial on installing the libraries via the board manager in Arduino IDE and implement the fix yourself. I used Arduino IDE 1.6.7 at the time of this writing.

The needed fix is one line in the VirtualWire library that comes with Digispark. Find the VirtualWire.cpp file (on OSX it's located in /Users/[user]/Library/Arduino15/packages/digistump/hardware/avr/1.6.5/libraries/VirtualWire/) and on line 273 add "const" at the beginning, otherwise the compiler will bitch about it (and tell you exactly where the issue is). It should look like this:

const uint8_t prescalers[] PROGMEM = {0, 0, 3, 6, 8, 10, 12}; /* Must be outside the function */

Before the microcontroller can be programmed from Arduino IDE via USB it needs to be loaded with the micronucleus firmware. I installed the 1.11 version. The Digispark library comes with the micronucleus uploading tool for 1.x firmware, it does not work on 2.x ones.

Download the Github files for micronucleus firmware and extract them wherever. Connect the ATtiny to your computer via your trusty ISP programmer (I used USBasp) and upload the firmware using the following command.

avrdude -c usbasp -b 19200 -p t85 -U flash:w:micronucleus-1.11.hex -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m

Finally it seems the Digispark libraries have some authority issues on OSX, the uploading tools have a missing executable flag, so add it manually:

chmod +x /Users/[user]/Library/Arduino15/packages/digistump/tools/micronucleus/2.0a4/launcher
chmod +x /Users/[user]/Library/Arduino15/packages/digistump/tools/micronucleus/2.0a4/micronucleus
Now you can upload files comfortably form Arduino IDE via USB. You need to unplug and replug the device after clicking the Upload button in Arduino IDE each time though.

Take a moment and marvel over what has been achieved here, USB protocol if a fussy one that requires impeccable timing, now it runs on an ATtiny which, in addition, can reprogram its flash memory and execute a bunch of other things... that's some very sexy optimisation right there.

Discussions