Raspberry Pi - Flash Arduino




Flash Arduino from Raspberry (by SSH console)

This example shows how to install all required ARDUINO libraries and compliers to compile and flash my arduino code for the front garden sensor using different Grove-Sensors, NeoPixels and OneWire a SHT-10 based soil sensor from Adafruit (which by the way is crap, because it can not handle water condensation). The Ardunio UNO is connected to the RaspberryPi by USB.

Install the required applications

 ssh -l root raspberry.lan
    
 apt-get update
 apt-get install arduino-mk

Specify some Environment Variables

 echo " " >> /root/.profile
 echo "export BOARD=uno" >> /root/.profile
 echo "export SERIALDEV=/dev/ttyACM0" >> /root/.profile
 echo "export ARDUINO_PORT=/dev/ttyACM0" >> /root/.profile
 echo "export ARDUINO_DIR=/usr/share/arduino" >> /root/.profile
 echo "export ARDUINO_LIBS=\"Sensirion OneWire DallasTemperature Adafruit_NeoPixel"\" >> /root/.profile
    
 source /root/.profile

Copy all required Ardunio libraries to the Raspberry

For my code five additional libraries are required:

Either copy from your system:
scp -r /Users/ma/dev/Ardunio/libraries/* root@192.168.123.52:/usr/share/arduino/libraries/
Or download them:
 cd /usr/share/arduino/libraries/
    
 wget http://www.homecontrols.ch/bin/Adafruit_NeoPixel.zip
 wget http://www.homecontrols.ch/bin/DallasTemperature.zip
 wget http://www.homecontrols.ch/bin/OneWire.zip
 wget http://www.homecontrols.ch/bin/Sensirion.zip
 wget http://www.homecontrols.ch/bin/SHT1x.zip
    
 unzip Adafruit_NeoPixel.zip
 unzip DallasTemperature.zip
 unzip OneWire.zip
 unzip Sensirion.zip
 unzip SHT1x.zip
    
 rm Adafruit_NeoPixel.zip
 rm DallasTemperature.zip
 rm OneWire.zip
 rm Sensirion.zip
 rm SHT1x.zip

Create Makefile and Ardunio Code

Put olny one *ino-file (or project) into this directory

 mkdir /opt/ardunio
 cd /opt/ardunio
 cp /usr/share/arduino/Arduino.mk .
 cp /usr/share/arduino/Common.mk .
 mv Arduino.mk Makefile
 ls /opt/ardunio/front.ino # This file contains my Ardunio Code (to access the sensors)
 make # just compile it
 make upload

The Error messages are quite descriptive. Here the output from the flashing:

 /usr/bin/avr-g++ -MM -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/Sensirion -I/usr/share/arduino/libraries/OneWire -I/usr/share/arduino/libraries/DallasTemperature -I/usr/share/arduino/libraries/Adafruit_NeoPixel -I/root/sketchbook/libraries/Sensirion -I/root/sketchbook/libraries/OneWire -I/root/sketchbook/libraries/DallasTemperature -I/root/sketchbook/libraries/Adafruit_NeoPixel -I/root/sketchbook/libraries/math -g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions build-cli/front.cpp -MF build-cli/front.d -MT build-cli/front.o
 cat build-cli/front.d > build-cli/depends.mk
 for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \
 do $STTYF /dev/tty >/dev/null 2>&1 && break ; \
 done ; \
 $STTYF /dev/ttyACM0  hupcl ; \
 (sleep 0.1 2>/dev/null || sleep 1) ; \
 $STTYF /dev/ttyACM0 -hupcl
 /usr/bin/avr-g++ -c -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/Sensirion -I/usr/share/arduino/libraries/OneWire -I/usr/share/arduino/libraries/DallasTemperature -I/usr/share/arduino/libraries/Adafruit_NeoPixel -I/usr/share/arduino/libraries/math -I/root/sketchbook/libraries/Sensirion -I/root/sketchbook/libraries/OneWire -I/root/sketchbook/libraries/DallasTemperature -I/root/sketchbook/libraries/Adafruit_NeoPixel -I/root/sketchbook/libraries/math -g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions build-cli/front.cpp -o build-cli/front.o
 /usr/bin/avr-gcc -mmcu=atmega328p -Wl,--gc-sections -Os -o build-cli/ardunio.elf build-cli/front.o build-cli/libcore.a  -lc -lm
 /usr/bin/avr-objcopy -O ihex -R .eeprom build-cli/ardunio.elf build-cli/ardunio.hex
 /usr/bin/avrdude -q -V -p atmega328p -C /etc/avrdude.conf -c arduino -b 115200 -P /dev/ttyACM0  \
 -U flash:w:build-cli/ardunio.hex:i
        
 avrdude: AVR device initialized and ready to accept instructions
 avrdude: Device signature = 0x1e950f
 avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
 To disable this feature, specify the -D option.
 avrdude: erasing chip
 avrdude: reading input file "build-cli/ardunio.hex"
 avrdude: writing flash (12876 bytes):
 avrdude: 12876 bytes of flash written
        
 avrdude: safemode: Fuses OK
        
 avrdude done.  Thank you.