Setting up a Raspberry Pi Arduino environment for stepZero R1

In order to upload code to your stepZero, you will need to install Arduino and add the files needed to support the Sanguino Attmega1284p core.

Begin by installing Git if it’s not already installed

sudo apt-get update
sudo apt-get install git

Install Arudino

sudo apt-get install arduino-core arduino-mk
sudo usermod -a -G dialout pi

Change pi to be your username if different

Enable auto reset during sketch upload

stepZero uses Raspberry Pi pin 12 (GPIO18)  to reset the Attmega1284p core. See here for more information on the steps bellow.

git clone https://github.com/deanmao/avrdude-rpi.git
cd avrdude-rpi
nano autoreset

Modify this part (see the parts in BOLD)

def reset():
pin = 12
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
time.sleep(0.12)
GPIO.output(pin, GPIO.HIGH)
GPIO.cleanup()

Press Ctrl-O and enter to save the file, then Cntrl-X to exit the text editor.

sudo cp autoreset /usr/bin
sudo cp avrdude-autoreset /usr/bin
sudo mv /usr/bin/avrdude /usr/bin/avrdude-original
sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude

Add support for Sanguino

cd ~
git clone https://github.com/Lauszus/Sanguino.git
sudo cp Sanguino/variants/sanguino/pins_arduino.h /usr/share/arduino/hardware/arduino/cores/arduino/
sudo nano /usr/share/arduino/hardware/arduino/boards.txt

The last command will open a text file in a text editor. Add the following to the bottom of the file:

#######################################################

stepZero.name=stepZero Sanguino W/ ATmega1284P (20 MHz)

stepZero.upload.maximum_size=130048
stepZero.upload.maximum_data_size=16384

stepZero.upload.protocol=arduino
stepZero.upload.speed=115200
stepZero.bootloader.path=optiboot
stepZero.bootloader.file=optiboot_atmega1284p.hex

stepZero.bootloader.low_fuses=0xFF
stepZero.bootloader.high_fuses=0xDE
stepZero.bootloader.extended_fuses=0xFD
stepZero.bootloader.unlock_bits=0x3F
stepZero.bootloader.lock_bits=0x0F

stepZero.build.mcu=atmega1284p
stepZero.build.f_cpu=20000000L
stepZero.build.board=AVR_SANGUINO
stepZero.build.core=arduino:arduino
#stepZero.build.variant=sanguino

Press Ctrl-O and enter to save the file, then Cntrl-X to exit the text editor.

Uploading Arduino code

You will need to create a Makefile (without any extensions) in your Ardunio sketch folder (the folder containing your .ino file) and add the following in it

ARDUINO_DIR = /usr/share/arduino
BOARD_TAG    = stepZero
ARDUINO_PORT = /dev/serial0
ARDUINO_LIBS =
include /usr/share/arduino/Arduino.mk

To compile your code without uploading, use the command “make” inside your Ardunio sketch folder. Use the command “make upload” to compile and upload your code to the stepZero.

Tip: use a github repository for your Arduino programs, then you can develop your code on your computer then send to your Pi remotely. You can even automate the process if downloading the latest code, and uploading it to your stepZero, on every boot. More on this will be added soon.