============== Arduino ============== .. contents:: Indice degli argomenti .. |date| date:: Vim setup ========== #. Creare il path: ``/usr/share/vim/vimfiles/syntax`` #. Scaricare il file della sintassi: ``wget http://www.vim.org/scripts/download_script.php?src_id=15821 -o arduino.vim`` #. Aggiungere a ~/.vimrc ``autocmd! BufNewFile,BufRead *.ino setlocal ft=arduino`` Nell'IDE settare nelle File-> Preferences di usare un editor esterno: ogni volta in fase di compilazione aggiornera' il sorgente da disco. Compilazione CLI ================= 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: #. Sostituito i ``pde`` in ``ino`` per le estensioni #. Sostituito ``WProgram.h`` con ``Arduino.h`` #. Modificati tutti gli include di arduino.pin.h in vari file, mettendo in hardcoded ``/usr/share/arduino//hardware/arduino/variants/standard/pins_arduino.h`` Scripts ========= 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 Sid ======= /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 Boards ============ Pro Mini 5v --------------- 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 da usare con http://www.banggood.com/FT232RL-FTDI-USB-To-TTL-Serial-Converter-Adapter-Module-For-Arduino-p-917226.html infilare l'arduino nei pin del FTD con i processori rivolti uno verso l'altro. IDE: - programmer: USBasp - tipo arduino: Arduino pro mini 5v 16mhz atmega 328p AVR ================= Per utilizzare Arduino come un Normale AVR senza il framework di Arduino Core + Wiring si puo' prodere in due modi: 1. Lasciare una scheda, es una Uno, come configurata e' caricare tramite il bootloader caricato del codice che non utilizza il framework di Arduino. Questo semplifica tutto ma non permette di accedere a tutti i registri, ad es PB7 e PB8 vengono utilizzati per le connessioni ai cristalli. 2. Wipare il bootloader da un atmega328p (chip di un arduino uno) e cambiare lo stato dei fusibili per utilizzare l'oscillatore interno (8mhz, 10% di imprecisione) e liberare i PIN. In questo modo si potra' utilizzare tutti i PIN Arduino con bootloader -------------------------- 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) Senza bootloader ====================== 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'. * Fuse Calculator: http://www.engbedded.com/fusecalc 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 - Mappatura PIN Arduino - AVR 328P: https://www.arduino.cc/en/Hacking/Atmega168Hardware - Gestione bootloader: https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader - Opaioni per fusibili: http://waihung.net/using-internal-oscillator-on-atmega328p/ - File di esempio (includes) per AVR: https://github.com/hexagon5un/AVR-Programming Condensatore per evitare il reset ----------------------------------- 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. Ripristinare Arduino ---------------------- 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.