Programming ATtiny85 from Arduino Nano - The Challenge
In December 2022, this blog's author was given a challenge to implement a way to upload sketches to ATtiny85. There are many examples that use the Uno to program the ATtiny85.
As a self-imposed challenge an Arduino Nano would need to be used as the programmer. Being relatively new to the Arduino world at that time, research was started to find out the prerequisites to achieve this. This blog post is the first of a series, describing the process.
THIS BLOG POST IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THIS HOWTO OR SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS BLOG POST.
Searching the Internet several videos and pages were found regarding this topic. Here are some that might peek your interest.
- Arduino as ISP and Arduino Bootloaders
- How-To: Shrinkify Your Arduino Projects
- Matching Article: How-To: Shrinkify Your Arduino Projects
- How to Program an Attiny85 From an Arduino Uno
- Program ATtiny85 with Arduino Nano
- Programming ATtiny85/84 with Arduino Uno (ATTinyCore)
- Program the ATTINY85 with Arduino 1.8.18 (2022)
In on of the references, the ICSP header is used, rather than the pins D11, D12 and D13 as seen in most examples. Because of the header name, this also seems to have been the intented use for an Arduino board as a programmer. Looking at the ISP example 'ArduinoISP.ino' in the Arduino IDE below File -> Examples -> 11. ArduinoISP -> ArduinoISP, the comment reads:
// By default, the hardware SPI pins MISO, MOSI and SCK are used to communicate // with the target. On all Arduinos, these pins can be found // on the ICSP/SPI header: // // MISO °. . 5V (!) Avoid this pin on Due, Zero... // SCK . . MOSI // . . GND
This is confirmed on e.g. https://arduino.stackexchange.com/a/30027, where it states: "The standard connection for the ISP is a 100 mil 6-pin header (2x3)." The image from this answer shows the pin assignment for the ICSP header of the Uno:
1 2 MISO . . VTG SCK . . MOSI RST . . GND 5 6
With both Uno and Nano rotated with the USB port pointing to the left you may notice that pin 1 is at the botom for the Nano, not at the top as with the Uno. If you look at it from that orientation, this is the pin assignment for the ICSP header of the Nano:
6 5 GND . . RST MOSI . . SCK VTG . . MISO 2 1
This confused me a bit at first, but it's the exact same header. It just depends on the board's orientation where to find the correct pin numbers.
Lesson learned: Make sure to locate pin 1, before connecting cables.
Look for a small dot or a small 1.
TODO add macro photo's from Uno and Nano pin 1 indication
The key pins for ICSP seem to be MISO, MOSI and SCK. After locating them on the Nano ICSP header, the matching pins on the ATtiny85 also need to be located. As suggested in the references, look for the chip's datasheet and find the section that describes the pins.
Now the needed data to connect the wires is available for both the programmer (Nano) and the peripheral (ATtiny85). From that we can deduct what to connect where and assign some colors for the wires.
Nano ICSP Header ATtiny85 wire color Pin 1 MISO Pin 6 PB1 (MISO) Blue Pin 2 +5V Pin 8 VCC Red Pin 3 SCK Pin 7 PB1 (SCK) White Pin 4 MOSI Pin 6 PB0 (MOSI) Brown Pin 6 GND Pin 4 GND Black Nano standard pin Pin D10 Pin 1 PB5 (RESET) Orange
In ref 1 and in the ArduinoISP example, there is a comment on using LEDs (with resistor), to indicate the status of the programmer.
// Put an LED (with resistor) on the following pins: // 9: Heartbeat - Shows the programmer is running // 8: Error - Lights up if something goes wrong (use red if that makes sense) // 7: Programming - In communication with the slave
This was added to the challenge aswell. This led to a design for Arduino Nano to be used as a programmer for ATtiny85 via the ICSP header with indicator LEDs.
The next blog post will feature the design.