HOME  |   ENGINEERING  |   RESEARCH  |   CONTACT
Computer Engineering Projects
Programming the ATTiny85 with the Raspberry PI Zero

Overview

This is an overview of the steps we followed to configure the Raspberry Pi to program the ATiny85.


Headless Setup
How to Setup the Raspberry Pi Zero Headless by Core-Electronics.

1. Setup Connection Details for the wifi ssid and password on the Raspberry Pi Zero W. In the root directory of the SD card (containing Raspberry Pi operating system), create the following two files:
File: wpa_supplicant.conf
network={
  ssid="myssid"
  psk="mypassword"
  key_mgmt=WPA-PSK
}

File: ssh
 
Notice that the ssh file is empty, but serves to tell the Raspberry Pi to open a SSH port at boot one time only.

2. Log on to the Raspberry Pi using a SSH client (you'll have to find its IP address) and enter the username and password. For a new device the default username is pi and password is raspberry.

3. Enable SSH in the configuration tool by typing the following at the prompt:
$ sudo raspi-config
Remember also to change the password!


Program ATTiny85 from Raspberry Pi
Programming the ATtiny85 from the Raspberry Pi instructible by prb333.

1. Enable SPI by starting the configuration manager from the commandline and enabling the SPI interface:
$ sudo raspi-config

2. Download and Build AVRDude using the following commands:
$ sudo apt-get update
$ sudo apt-get install bison automake autoconf flex git gcc
$ sudo apt-get install gcc-avr binutils-avr avr-libc
$ git clone https://github.com/kcuzner/avrdude
$ cd avrdude/avrdude
$ ./bootstrap && ./configure && sudo make install

3. Download and Build WiringPi for the GPIO commands:
$ cd ~
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build

4. Electrical Connections

The connection can be tested using the following code. Note that the GPIO pin 22 resets the ATtiny for programming.
$ sudo gpio -g mode 22 out
$ sudo gpio -g write 22 0
$ sudo avrdude -p t85 -P /dev/spidev0.0 -c linux -b 10000
$ sudo gpio -g write 22 1

5. Create a Program to flash the LED by creating the directory, file, and makefile as follows:
$ cd ~
$ mkdir attiny85
$ cd attiny85
$ mkdir blinky
$ cd blinky

Create the blinky.c file using the command:
$ nano blinky.c

File: blinky.c
#define F_CPU 1000000L
#include <avr/io.h>
#include &util/delay.h>
int main(void)
  DDRB = 0xFF; // PORTB is output, all pins
  PORTB = 0x00; // Make pins low to start
  for (;;)
  {
    PORTB ^= 0xFF; // Invert all the pins
    _delay_ms(100); // Wait some time
  }
  return 0;
}

Create the Makefile using the command:
$ nano Makefile

File: Makefile
MCU=attiny85
AVRDUDEMCU=t85
CC=/usr/bin/avr-gcc
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=$(MCU)
OBJ2HEX=/usr/bin/avr-objcopy
AVRDUDE=/usr/local/bin/avrdude
TARGET=blinky
all :
  $(CC) $(CFLAGS) $(TARGET).c -o $(TARGET)
$(OBJ2HEX) -R .eeprom -O ihex $(TARGET) $(TARGET).hex
  rm -f $(TARGET)
install : all
  sudo gpio -g mode 22 out
  sudo gpio -g write 22 0
  sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:$(TARGET).hex
  sudo gpio -g write 22 1
noreset : all
  sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:$(TARGET).hex
fuse :
  sudo gpio -g mode 22 out
  sudo gpio -g write 22 0
  sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
  sudo gpio -g write 22 1
clean :
  rm -f *.hex *.obj *.o

To compile and upload the code, type:
$ make install

To send the fuses, type:
$ make fuse



PROJECTS

» Softlatch Project
   Power latch with software power-off function
» INA219 Serial Project
   Serial ammeter for project USB supply
» AuraBean Project
   Probability and sensitivity research tool
» AuraBean II Project
   Web-enabled probability and sensitivity research tool
» Guessology Games
   Random browser-based guessing games


HOW-TO

» Raspberry Pi Programmer
   Programs ATTiny85 microcontrollers
» Pycom WiPy Setup
   Setup and program the WyPi



© 2020 Cedric Joyce