-
Notifications
You must be signed in to change notification settings - Fork 11
Programming the ATTiny
I assume that you have some familiarity with the Arduino IDE, because we will use it to program the ATTiny. You might ask, why not a real development IDE, but an underlying decision was to make building this thing as simple as possible, and this means the Arduino IDE.
If you have never programmed a bare-bones micro-controller before then the following will be a new experience, but the process is as simple as programming an Arduino Nano, even though there are a few more steps.
First download and install the Arduino IDE.
Then install the additional board definition by https://github.com/damellis/attiny (there should be enough tutorials if you do not yet know how to do it).
Finally we need an I2C implementation for the USI of the ATTiny. This can be found in the Library Manager of the ArduinoIDE or alternatively here: https://github.com/puuu/USIWire
Most probably the compiled software will work with newer version of the libraries and Arduino IDE as well, but I worked with the following version:
- The Arduino IDE version used is 1.8.13
- There are two board definitions that can be used. I am using the ATTinyCore definition by Spence Konde.
- The ATTiny Board definition provided by https://github.com/damellis/attiny hasn‘t been changed since 2016. No release exists, but I do not assume that it will change anytime soon.
- The ATTinyCore definition provided by by https://github.com/SpenceKonde/ATTinyCore now works with the code without problems. In addition it provides a menu to choose different BOD-Levels so with this there is no need to edit board definitions by hand.
- The USIWire-implementation used is based on https://github.com/puuu/USIWire but modified by me and can be downloaded here: https://github.com/jbaumann/USIWire
In earlier versions of my code and the ATTinyCore, the resulting binary generated a lot of problems when reading over the I2C. This is no longer the case, and since this core is developed actively and the resulting binaries are no longer larger than the ones created with the old ATTiny board definition, I have switched to it.
Download all the files in the firmware subdirectory and open the corresponding directory in your Arduino IDE. Now change the target to „ATTiny 25/45/85“, change the processor to „ATTiny85“, and choose „8MHz(internal)“ as the processor frequency. Hit the compile button and the result should be a firmware you can flash to the ATTiny in the next step.
In the main file ATTiny_Daemon.ino there are a number of variables that are pre-initialized with sensible values. These can be changed, but I would advise against it, because they are safe for the first start and can later be changed without problems from the Raspberry. Most of these will be written to the EEPROM on the first start to survive resets of the ATTiny.
The last step is to send the code to the chip. I recommend to use a very nice programmer by Burgduino that provides the functionality to reset all fuses (High-Voltage-Programmer) in addition to its normal programmer functionality AFRP-V200 or an USBASP in-circuit programmer which is amazingly simple to use. But if you have e.g. an Atmel AVRISP mk.II then that works equally well. Or you can use an Arduino to program your ATTiny. Simply choose your programmer in the IDE.
The next step is to write the fuses that are providing the BOD detection, define the used clock frequency and other functionality (here is the explanation: https://github.com/jbaumann/attiny_daemon/wiki/Burning-the-Fuses). You do this by choosing the menu option "Burn Bootloader".
Now press the "Upload"-Button. We are uploading the firmware without any bootloader. Since we work with a barebone chip there are no disadvantages. The advantage for our case is that the chip boots at once into its setup()-function without any delay, which lets us react faster to restarts in precarious circumstances (i.e., with the power being around or below the shutdown power level).
If the upload was successful, remove the chip and place it on your board. This could be either a breadboard if you want to experiment, could be a proto board you soldered or the PCB that is provided in the hardware folder.
Now, without connecting your board to the Raspberry, simply provide 3.3-5V to using the GND and Battery pins. The LED should start to flash in 1 second intervals. If that is the case, everything should work and you can plug it into the Raspberry Pi.
The version 1.7 and 1.8 of the PCB has to be installed on pins 3, 4, 5, 6 with the ATTiny oriented inwards (i.e., hovering above the RPi). This means two pins are left of our four-pin female header. Please be careful to select the correct placement and verify it again before connecting the system to power.
There shouldn‘t be a problem if the connector is placed one row to the left or right of the correct position, or even if it is plugged in on the wrong end of the header. The only way I see (without practical tests) to possibly destroy something is by installing the board facing outwards. But you won‘t do that, won‘t you?
The version 1.8shim of the PCB is simply installed on the first 3 columns of the header (i.e. pins 1-6). We do not need the outermost pins, but use them for additional stability. Additionally the probability of connecting the PCB to the header the wrong way is even lower than before. I would suggest that you use this variant (I do).
Ok, and now check the placement of the board again.