Indice degli argomenti
Nell’IDE settare nelle File-> Preferences di usare un editor esterno: ogni volta in fase di compilazione aggiornera’ il sorgente da disco.
Quanto segue e’ riferito al pacchetto rduino-core 1:1.0+dfsg-4. Il makefile utilizzato:
ARDUINO_DIR = /usr/share/arduino
#TARGET = Blink // Name of Sketch
#ARDUINO_LIBS = LiquidCrystal // Extra libs
BOARD_TAG = uno // This is working on a Arduino uno r.2
MCU = atmega328p // Uno has a 328P low power chip
F_CPU = 16000000L
ARDUINO_PORT = /dev/ttyACM0
VARIANTS = $(INSTALL_DIR)/hardware/arduino/variants/standard
AVRDUDE_ARD_PROGRAMMER = arduino
AVRDUDE_ARD_BAUDRATE = 115200
include /usr/share/arduino/Arduino.mk
Che include /usr/share/arduino/Arduino.mk.
Estratto:
# 0.5 23.iii.2011 Stefan Tomanek
# - added ad-hoc library building
Modificato in vari punti:
A couple of scripts to invoke the compiler.
ara.sh
#!/bin/sh
# Make and optional make clean to compile | verify an arduino sketch.
make --quiet -f /root/flow/sketchbook/Makefile TARGET=$1 $2
arup.sh
#!/bin/sh
# Upload a sketch to the Arduino board
make --quiet -f /root/flow/sketchbook/Makefile TARGET=$1 upload
/usr/share/arduino/Makefile
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
BOARD_TAG = uno
MONITOR_PORT = /dev/ttyACM0
CURRENT_DIR = $(shell pwd)
OBJDIR = /tmp/$(notdir $(shell pwd))
ARDUINO_DIR = /usr/local/software/arduino-1.6.5
MONITOR_BAUDRATE = 115200
include /usr/share/arduino/Arduino.mk
Creare un alias per copiare il Makefile nella dir corrente, aggiungere una voce corrispondente in .gitignore
Arduino Compatible 5V 16M Pro Mini Microcontroller Board Improved AtMega328P 328 - http://www.banggood.com/5Pcs-Arduino-5V-16M-Pro-Mini-Microcontroller-Improved-AtMega328P-p-951795.html
infilare l’arduino nei pin del FTD con i processori rivolti uno verso l’altro.
IDE:
Per utilizzare Arduino come un Normale AVR senza il framework di Arduino Core + Wiring si puo’ prodere in due modi:
Usare la IDE di Arduino utilizzando i parametri normali per l’upload di uno sketch. Per avrdude si usa una stringa tipo:
avrdude -c arduino -p atmega328p -P /dev/ttyUSB0 -U flash:w:blinkLED.hex:
avrdude -c arduino -p atmega328p -P /dev/ttyUSB0 -U flash:w:blinkLED.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
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 "blinkLED.hex"
avrdude: input file blinkLED.hex auto detected as Intel Hex
avrdude: writing flash (178 bytes):
Writing | ################################################## | 100% 0.04s
avrdude: 178 bytes of flash written
avrdude: verifying flash memory against blinkLED.hex:
avrdude: load data flash data from input file blinkLED.hex:
avrdude: input file blinkLED.hex auto detected as Intel Hex
avrdude: input file blinkLED.hex contains 178 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.03s
avrdude: verifying ...
avrdude: 178 bytes of flash verified
avrdude: safemode: Fuses OK (E:00, H:00, L:00)
avrdude done. Thank you.
Makefile:
##########------------------------------------------------------##########
########## Project-specific Details ##########
########## Check these every time you start a new project ##########
##########------------------------------------------------------##########
MCU = atmega328p
F_CPU = 16000000UL
BAUD = 9600UL
## Also try BAUD = 19200 or 38400 if you're feeling lucky.
## A directory for common include files and the simple USART library.
## If you move either the current folder or the Library folder, you'll
## need to change this path to match.
LIBDIR = ../../AVR-Programming-Library
##########------------------------------------------------------##########
########## Programmer Defaults ##########
########## Set up once, then forget about it ##########
########## (Can override. See bottom of file.) ##########
##########------------------------------------------------------##########
PROGRAMMER_TYPE = arduino
# extra arguments to avrdude: baud rate, chip type, -F flag, etc.
PROGRAMMER_ARGS = -P /dev/ttyACM0
#PROGRAMMER_ARGS = -C /usr/local/software/arduino-1.6.5/hardware/arduino/avr/bootloaders/gemma/avrdude.conf -v -v -v -v -b 57600 -P /dev/ttyACM1
TODO: non e’ chiaro a che bps viene fatto l’upload.
Standard configuration:
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: erasing chip
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (E:00, H:00, L:00)
Per i fusibili in modo da usare l’oscillatore interno a 1MHz (default di fabbrica) o 8Mhz:
avrdude -c avrisp -p atmega328p -b 19200 -P /dev/ttyACM0 -v -U lfuse:w:0x62:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
avrdude -c avrisp -p atmega328p -b 19200 -P /dev/ttyACM0 -v -U lfuse:w:0xe2:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
Lettura dello stato del chip a 1MHz:
avrdude -c avrisp -p atmega328p -b 19200 -P /dev/ttyACM1
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.05s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62)
avrdude done. Thank you.
Per Ripristinare i fusibili allo stato originale di Arduino Uno utilizzare la procedura di scrittura del bootloader e di uno sketch. Si ricorda che suciessivamente senza un oscillatore il chip non partira’.
Per i suciessivi upload tramite avrisp (usando come programmatore una Uno con Avrisp caricato e un condensatore tra RESET e GND):
avrdude -c avrisp -p atmega328p -b 19200 -P /dev/ttyACM0 -U flash:w:blinkLED.hex
Esempio di Makefile:
##########------------------------------------------------------##########
########## Project-specific Details ##########
########## Check these every time you start a new project ##########
##########------------------------------------------------------##########
MCU = atmega328p
F_CPU = 1000000UL
BAUD = 9600UL
## Also try BAUD = 19200 or 38400 if you're feeling lucky.
## A directory for common include files and the simple USART library.
## If you move either the current folder or the Library folder, you'll
## need to change this path to match.
LIBDIR = ../../AVR-Programming-Library
##########------------------------------------------------------##########
########## Programmer Defaults ##########
########## Set up once, then forget about it ##########
########## (Can override. See bottom of file.) ##########
##########------------------------------------------------------##########
PROGRAMMER_TYPE = avrisp
# extra arguments to avrdude: baud rate, chip type, -F flag, etc.
PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0
#PROGRAMMER_ARGS = -C /usr/local/software/arduino-1.6.5/hardware/arduino/avr/bootloaders/gemma/avrdude.conf -v -v -v -v -b 57600 -P /dev/ttyACM1
Si noti il BPS -p 19200, resettare la scheda programmatrice prima di lanciare un nuovo upload in caso di fallimento del precedente. Non usare come DEBUG un LED sui PIN da 13->7 : questi sono mappati sulla connessione ISP.
Schemi: https://www.arduino.cc/en/Tutorial/ArduinoISP
Utilizzando una Arduino Uno si dovrebbe tenere un condensatore di almeno 10uF (meglio anche qualcosa in piu’, tipo uno scarto di una scheda madre da 1000uF che impieghera’ 6/7 secondi a caricarsi - resettare) per evitare che avrdude contattando la scheda madre possa resettarla, interrompere lo sketch ArduinoISP e tentare di caricare lo sketch sulla scheda (cosa che non dovrebbe succedere se avrdude usa il flag -c avrisp ma talvolta la IDE non lo usa!) invece che sul target.
Con un bootloader recente il condensatore non dovrebbe essere necessario dato che il flag -c avrisp dovrebbe mandare un codice che non resetta la scheda Arduino Uno che esegue lo sketch ArduinoISP.
Per ripristinare il chip atmega328p allo stato originale (fusibili e bootloader) procedere alla riscrittura del bootloader dalla Arduino IDE, questo dovrebbe riconfigurare anche i fusibili per l’oscillatore interno.
Si noti che se il chip e’ stato settato per utilizzare un oscillatore esterno come sulla scheda Arduino Uno e simili non partira’ senza un segnale di clock su PB6 e PB6, nel caso serve un oscillatore ed eventualmente un paio di capacitors.