Arduino

From EWIKI
Jump to navigation Jump to search

Tutorials + Examples

https://www.arduino.cc/en/Guide/Linux

ls -l /dev/ttyUSB0 
sudo usermod -a -G dialout <user>

weitere nützliche Seiten:

Feature Comparison

Processor Board Flash EEPROM SRAM IO AD PWM
ATMega2560 Robodyne 256kB 4kB 8kB 54 16 5
ATMega32u4 ProMicro 32kB 1kB 2.5kB 14 12 6
ATmega328 ProMini 32kB 1kB 2kB 14 8 6
ATmega328 ProMini 32kB 1kB 2kB 14 6 6

see also https://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems

Arduino Uno

Arduino-Uno.png

Pins

  • I2C
    • SCL = A5 (analog port!!)
    • SDA = A4 (analog port!!)

https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf

Aruino Pro Mini

Homepage: https://www.arduino.cc/en/Main/ArduinoBoardProMini

Arduino ProMini.JPG


ISP:

  • MOSI: 11
  • MISO: 12
  • SCK: 13
  • RST
  • VCC
  • GND

I2C:

  • SDA: A4
  • SCL: A5

ATmega 328P-PU + Arduino GUI: via AVR-ISP mk2 programmieren =

siehe Aruino Tutorials: ISP

ISP: ISP-Con.jpg

  • 8 MHz Quarz + 2x C = 15 pF nach GND
  • Reset + Pull Up 20k
  • 17 MOSI
  • 18 MISO
  • 19 SCK

ATmega 328 Pinout: https://www.arduino.cc/en/Hacking/PinMapping168

Arduino IDE:

  • Tools: Board: "Duemilanove w/ ATmega328"
  • Sketch: Upload using programmer

... also ohne Bootloader!!

avrdude on command line:

Set fuses (http://www.engbedded.com/fusecalc)

  • lfuse:
    • 0x22: int 8 MHz div 8 (default)
    • 0xFF: ext Quartz 16 MHz
  • hfuse:
  • efuse: BODLEVEL1 Brown-out Detector trigger level
avrdude -P usb -c avrisp2 -p m328p -v -e -U efuse:w:0x05:m -U hfuse:w:0xD6:m -U lfuse:w:0xFF:m
avrdude -P usb -c avrisp2 -p m328p -v -e -U hfuse:w:0xD6:m -U lfuse:w:0xFF:m

Run: 1MHz int Osc

avrdude -P usb -c avrisp2 -p m328p -v -U lfuse:w:0x62:m

board.txt

##############################################################
mega1mhz.name=ATMega328p @ 1 MHz
mega1mhz.upload.tool=avrdude
diecimila.upload.protocol=arduino
mega1mhz.bootloader.tool=avrdude
mega1mhz.bootloader.low_fuses=0x62
mega1mhz.bootloader.unlock_bits=0x3F
mega1mhz.bootloader.lock_bits=0x0F
mega1mhz.build.f_cpu=1000000L
mega1mhz.build.board=AVR_DUEMILANOVE
mega1mhz.build.core=arduino
mega1mhz.build.variant=standard
## Arduino Duemilanove or Diecimila w/ ATmega328
## ---------------------------------------------
mega1mhz.menu.cpu.atmega328=ATmega328
mega1mhz.menu.cpu.atmega328.upload.maximum_size=30720
mega1mhz.menu.cpu.atmega328.upload.maximum_data_size=2048
mega1mhz.menu.cpu.atmega328.upload.speed=57600
mega1mhz.menu.cpu.atmega328.bootloader.high_fuses=0xDA
mega1mhz.menu.cpu.atmega328.bootloader.extended_fuses=0x05
mega1mhz.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex
mega1mhz.menu.cpu.atmega328.build.mcu=atmega328p


Upload bootloader

avrdude -P usb -c avrisp2 -p m328p -v -e -U flash:w:ATmegaBOOT_168_atmega328.hex -U lock:w:0x0F:m
avrdude -P usb -c avrisp2 -p m328p -v -e -U flash:w:ATmegaBOOT_168_atmega328_pro_8MHz.hex -U lock:w:0x0F:m

SpakrFun (Leonardo) Pro Micro

Achtung: Gib es als 3.3 V oder 5 V Version gejumpert!

LeonardoProMicro.JPG

I2C (ref https://www.arduino.cc/en/Hacking/PinMapping32u4)

  • SDA: Pin2
  • SCL: Pin3

ProMicro16MHzv2.png

Arduino Add Ons:


Burning Bootloader with UNO

Pin Pro Micro Uno
Reset 3 10
MOSI 11 11
MISO 10 12
SCK 9 13

1wire

cd ~/sketchbook/libraries/
git clone https://github.com/PaulStoffregen/OneWire.git
git clone https://github.com/milesburton/Arduino-Temperature-Control-Library.git
mv Arduino-Temperature-Control-Library DallasTemperature

... and in IDE > Sketch > Import

ino Programmer auf der Kommandozeile

Siehe: "ino" tool for command line compile an programmer

Die Verzeichnisstruktur ist etwas tricky, wenn man mit ArduinoIDE und ino parallel arbeiten möchte:

  • projektName/
    • src/
      • sketch/
        • sketch.ino
    • lib/
      • libName/

Arduino Nano

Arduino-nano-pins.png

Programming:

cd /snap/arduino-mhall119/current/Arduino/Blink
avrdude -c arduino -b 57600 -P /dev/ttyUSB0 -p atmega328p -vv -U flash:w:Blink.ino.eightanaloginputs.hex


Arduino IDE: ATmega 328P (old Bootloader)

i2c

TODO

OLED

TODO

I2C 8x8 LED Matrix

see Keyestudio LED Matrix


Timer 5 0n ATMega2560

  • Timer/Counter 0: 8 bit
    • delay(), millis(), micros(), analogWrite() pin 5/6
  • Timer/Counter 1: 16 bit
    • delay(), millis(), micros(), analogWrite() pin 9/10
  • Timer2 ??
    • analogWrite() pin 3/11
  • Timer/Counter 3: 16 bit
  • Timer/Counter 4: 16 bit
  • Timer/Counter 5: 16 bit
   CSn2 CSn1 CSn0
     0    0   1    clk I/O /1 (No prescaling
     0    1   0    clk I/O /8 (From prescaler)
     0    1   1    clk I/O /64 (From prescaler)
     1    0   0    clk I/O /256 (From prescaler)
     1    0   1    clk I/O /1024 (From prescaler)
 // -------------------------------------------------------------
 //   Blink ATMega2560 using Timer 5 
 // -------------------------------------------------------------
 const int LED_CH1_PIN = PA6; // or whatever pin we have here
 const uint16_t timer5_load = 0;
 const uint16_t timer5_comp = 31250;
 // -------------------------------------------------------------
 // the setup function runs once when you press reset or power the board
 void setup() {
   Serial.begin( 9600 ); // USB
   Serial.println("Starting...");
   initLEDs();
   initTimer5();
   // enable interrupts
   sei();
 }
 // -------------------------------------------------------------
 void initTimer5() {
   // No clock source (Timer/Counter stopped) 
   TCCR5A = 0x00; 
   // CS22=0 CS21=1 CS20=1 -> prescale = 256 (Timer/Counter started)
   TCCR5B |=  ( 1 << CS52 );
   TCCR5B &= ~( 1 << CS51 );             
   TCCR5B &= ~( 1 << CS50 );             
   // Register : the Timer/Counter (TCNT2) and Output Compare Register (OCR2A and OCR2B) are 8-bit
   // Reset Timer Count
   TCNT5 = timer5_load; 
   OCR5A = timer5_comp;
   TIMSK5 = ( 1 << OCIE5A ); 
 }
 // -------------------------------------------------------------
 ISR( TIMER5_COMPA_vect ) { /* Timer/Counter Compare Match A */
   TCNT5 = timer5_load;
   PORTA ^= ( 1 << LED_CH1_PIN );
 } 
 // -------------------------------------------------------------
 void initLEDs() {
   // set LED pin to be output
   DDRA |= ( 1 << LED_CH1_PIN );
 }
 // -------------------------------------------------------------
 void loop() {
   delay(1000);                       // wait for a second
 }

Links