class: center, middle # Einführung in Mikrocontroller --- ## Mikrocontroller > "Ein Mikrocontroller stellt im Prinzip einen Mikrorechner auf einem Chip dar. Ziel ist es, eine Steuerungs- oder Kommunikationsaufgabe mit möglichst wenigen Bausteinen zu lösen. Prozessorkern, Speicher und Ein-/Ausgabeschnittstellen eines Mikrocontrollers sind auf die Lösung solcher Aufgaben zugeschnitten. Durch die große Vielfalt möglicher Aufgabenstellungen existieren daher eine Vielzahl verschiedener Mikrocontroller, welche die Zahl verfügbarer Mikroprozessoren um ein Weites übertrifft." .red[[1]] .footnote[.red[[1]] "Mikrocontroller und Mikroprozessoren", T. Ungerer und U. Brinkschulte, 3. Auflage Berlin Heidelberg New York: Springer-Verlag, 2010. ] --- class: middle ## Wo finden wir Mikrocontroller im Alltag? --- class: middle ## Was ist der Unterschied zwischen PC und Mikrocontroller? --- ## ATmega328P (Arduino UNO) .center[![arduino uno](Barbone_Arduino_Uno.jpg)] .footnote[ [Bildquelle: Wikimedia Commons Barbone Arduino Uno](https://commons.wikimedia.org/wiki/File:Barbone_Arduino_Uno.jpg) ] --- ## Aufbau .center[![datasheet](328.png)] .footnote[ [Bildquelle: Atmel ATmega328P Datasheet S. 6](https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf) ] --- ## Speicher - Flash - Flash ist ein nicht-flüchtiger Speicher. Auch ohne Stromversorgung werden die Daten gespeichert. - Ein ATmega328P hat "32K bytes of in-system self-programmable flash program memory" - SRAM - Static Random Access Memory - statischer RAM. Flüchtiger Speicher! - Ein ATmega328P hat "2Kbytes internal SRAM " - EEPROM - Electrically Erasable Programmable Read-Only Memory* ist ein nicht-flüchtiger Speicher. - Ein ATmega328P hat "1Kbytes EEPROM" Achtung! "Write/erase cycles: 10,000 flash/100,000 EEPROM" --- # Timer Sind Funktionsmodul die zählen! .center[![datasheet](timer.png)] .footnote[ [Bildquelle: Atmel ATmega328P Datasheet S. 24](https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf) ] --- ## A/D Converter *analog-to-digital converter* bzw. Analog-Digital-Umsetzer wandelt ein analoges Signal in einen digitalen Wert. - ATmega328P hat eine 10-bit Auflösung (0-1023) - ATmega328P misst zwischen "0 to VCC ADC input voltage range" - ATmega328P hat "6 multiplexed single ended input channels" --- ## Oscillator .center[![Osci](osci.jpg)] .footnote[ [Bildquelle: Wikimedia Commons Arduino Crystal](https://commons.wikimedia.org/wiki/File:Arduino_crystal-1.jpg) ] --- ## Arduino UNO Rev3 .center[![schematics arduino uno rev3](schematics.png)] .footnote[ [Bildquelle: Arduino CC Schematics](https://docs.arduino.cc/static/c1593a4c4960ff7b51d1083cb8e45812/schematics.pdf) ] --- ## Installation Arduino IDE 1. Goto [https://www.arduino.cc/en/software](https://www.arduino.cc/en/software) 2. Download Software für dein OS 3. Installation --- ## Arduino Preferences - Dateispeicherort: - MAC OS X: ~/Library/Arduino15/preferences.txt - Windows: \Arduino15\preferences.txt - Linux: ~/.arduino15/preferences.txt Um mehr Einsicht in die Build- bzw Upload-Prozess zu bekommen bitte folgende Werte von *false* auf *true* ändern: - build.verbose=true - upload.verbose=true --- ## Boards Das richtige *Board* auswählen: *Tools* ➔ *Boards* ➔ *Arduino Uno* .center[![board](board.png)] --- ## Boardmanager: ESP32 Beim ESP32: *File* ➔ *Preferences* ➔ unter *Additional Boards Manager URLs:* Folgende Url eingeben: *https://dl.espressif.com/dl/package_esp32_index.json* ➔ *OK* *Tools* ➔ *Boards* ➔ *Boards Manager* ➔ Suchen nach ➔ *ESP32* und installieren! .center[![esp32](esp32.png)] --- ## USB-Port Den richtigen *Port* auswählen: *Tools* ➔ *Port* ➔ */dev/ttyUSB0* bzw *COM1* .center[![port](port.png)] --- ## Arduino Belegung .center[![pinout arduino uno rev3](A000066-full-pinout.png)] .footnote[ [Bildquelle: Arduino CC full pinout S.2](https://docs.arduino.cc/static/0ce63b05bd4614f09350f1dd947a0a20/A000066-full-pinout.pdf) ] --- ## setup() & loop() - void setup() - Lauf nur einmal beim Start des Arduinos! - Initialisiert und setzt die Anfangswerte - void loop() - It loops forever! - Diese Funktion wiederholt sich immer! - Das Programm kann nun Daten auslesen, Variablen abändern, usw. --- ## LED Blink Ziel der ersten Aufgabe ist es eine LED mittels Pin 11 ein- und auszuschalten! .center[![led aufbau](aufbau.png)] --- ## LED-Vorwiderstand ## ! ACHTUNG ! Eine LED würde an 5V nicht lange funktionieren (Magic Smoke)! Daher muss zur Begrenzung ein Widerstand vorgeschalten werden. - Rote LED verbraucht 1.6V & 20 mA - zu vernichtende Spannung sind 3.4 V (Arduino 5V!) - R = U/I - R = 3.4/0.02 - R = 170 Ohm - der nächste Wert ist 220 Ohm --- ## LED Blink Code ```C void setup() { pinMode(11, OUTPUT); //Der Pin 11 ist ein OUTPUT - pinMode(pin, mode) } void loop() { digitalWrite(11, HIGH); //Der Pin 11 wird eingeschalten(HIGH) - digitalWrite(pin, value) delay(1000); //Pause von 1000 Millisekunden, also einer Sekunde digitalWrite(11, LOW); delay(1000); } ``` .center[Und auf *Verify* (✓) klicken!] --- ## Verify: Arduino Console .center[Was passiert nun in der Arduino Console?] ```BASH /usr/share/arduino/arduino-builder -dump-prefs -logger=machine -hardware /usr/share/arduino/hardware -hardware /home/joak/.arduino15/packages -tools /usr/share/arduino/tools-builder -tools /home/joak/.arduino15/packages -libraries /home/joak/Arduino/libraries -fqbn=archlinux-arduino:avr:leonardo -vid-pid=10C4_EA60 -ide-version=10816 -build-path /tmp/arduino_build_989748 -warnings=none -build-cache /tmp/arduino_cache_755158 -prefs=build.warn_data_percentage=75 -verbose /usr/share/arduino/examples/01.Basics/Blink/Blink.ino /usr/share/arduino/arduino-builder -compile -logger=machine -hardware /usr/share/arduino/hardware -hardware /home/joak/.arduino15/packages -tools /usr/share/arduino/tools-builder -tools /home/joak/.arduino15/packages -libraries /home/joak/Arduino/libraries -fqbn=archlinux-arduino:avr:leonardo -vid-pid=10C4_EA60 -ide-version=10816 -build-path /tmp/arduino_build_989748 -warnings=none -build-cache /tmp/arduino_cache_755158 -prefs=build.warn_data_percentage=75 -verbose /usr/share/arduino/examples/01.Basics/Blink/Blink.ino Using board 'leonardo' from platform in folder: /usr/share/arduino/hardware/archlinux-arduino/avr Using core 'arduino' from platform in folder: /usr/share/arduino/hardware/archlinux-arduino/avr Detecting libraries used... /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /tmp/arduino_build_989748/sketch/Blink.ino.cpp -o /dev/null Generating function prototypes... /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /tmp/arduino_build_989748/sketch/Blink.ino.cpp -o /tmp/arduino_build_989748/preproc/ctags_target_for_gcc_minus_e.cpp /usr/bin/arduino-ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_989748/preproc/ctags_target_for_gcc_minus_e.cpp Compiling sketch... /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /tmp/arduino_build_989748/sketch/Blink.ino.cpp -o /tmp/arduino_build_989748/sketch/Blink.ino.cpp.o Compiling libraries... Compiling core... /usr/bin/avr-gcc -c -g -x assembler-with-cpp -flto -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/wiring_pulse.S -o /tmp/arduino_build_989748/core/wiring_pulse.S.o /usr/bin/avr-gcc -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/wiring_pulse.c -o /tmp/arduino_build_989748/core/wiring_pulse.c.o /usr/bin/avr-gcc -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/wiring_shift.c -o /tmp/arduino_build_989748/core/wiring_shift.c.o /usr/bin/avr-gcc -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/wiring_digital.c -o /tmp/arduino_build_989748/core/wiring_digital.c.o /usr/bin/avr-gcc -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/WInterrupts.c -o /tmp/arduino_build_989748/core/WInterrupts.c.o /usr/bin/avr-gcc -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/wiring_analog.c -o /tmp/arduino_build_989748/core/wiring_analog.c.o /usr/bin/avr-gcc -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/hooks.c -o /tmp/arduino_build_989748/core/hooks.c.o /usr/bin/avr-gcc -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/wiring.c -o /tmp/arduino_build_989748/core/wiring.c.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/PluggableUSB.cpp -o /tmp/arduino_build_989748/core/PluggableUSB.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/HardwareSerial2.cpp -o /tmp/arduino_build_989748/core/HardwareSerial2.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/HardwareSerial3.cpp -o /tmp/arduino_build_989748/core/HardwareSerial3.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/HardwareSerial.cpp -o /tmp/arduino_build_989748/core/HardwareSerial.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/CDC.cpp -o /tmp/arduino_build_989748/core/CDC.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/HardwareSerial0.cpp -o /tmp/arduino_build_989748/core/HardwareSerial0.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/IPAddress.cpp -o /tmp/arduino_build_989748/core/IPAddress.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/HardwareSerial1.cpp -o /tmp/arduino_build_989748/core/HardwareSerial1.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/Print.cpp -o /tmp/arduino_build_989748/core/Print.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/Stream.cpp -o /tmp/arduino_build_989748/core/Stream.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/Tone.cpp -o /tmp/arduino_build_989748/core/Tone.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/USBCore.cpp -o /tmp/arduino_build_989748/core/USBCore.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/WMath.cpp -o /tmp/arduino_build_989748/core/WMath.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/WString.cpp -o /tmp/arduino_build_989748/core/WString.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/abi.cpp -o /tmp/arduino_build_989748/core/abi.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/main.cpp -o /tmp/arduino_build_989748/core/main.cpp.o /usr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" -I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino -I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/leonardo /usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/new.cpp -o /tmp/arduino_build_989748/core/new.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/wiring_pulse.S.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/WInterrupts.c.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/hooks.c.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/wiring.c.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/wiring_analog.c.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/wiring_digital.c.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/wiring_pulse.c.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/wiring_shift.c.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/CDC.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/HardwareSerial.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/HardwareSerial0.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/HardwareSerial1.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/HardwareSerial2.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/HardwareSerial3.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/IPAddress.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/PluggableUSB.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/Print.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/Stream.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/Tone.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/USBCore.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/WMath.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/WString.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/abi.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/main.cpp.o /usr/bin/avr-gcc-ar rcs /tmp/arduino_build_989748/core/core.a /tmp/arduino_build_989748/core/new.cpp.o Archiving built core (caching) in: /tmp/arduino_cache_755158/core/core_archlinux-arduino_avr_leonardo_33334de5e2d3c2672266eacd2ab9ae3a.a Linking everything together... /usr/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega32u4 -o /tmp/arduino_build_989748/Blink.ino.elf /tmp/arduino_build_989748/sketch/Blink.ino.cpp.o /tmp/arduino_build_989748/core/core.a -L/tmp/arduino_build_989748 -lm /usr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino_build_989748/Blink.ino.elf /tmp/arduino_build_989748/Blink.ino.eep /usr/bin/avr-objcopy -O ihex -R .eeprom /tmp/arduino_build_989748/Blink.ino.elf /tmp/arduino_build_989748/Blink.ino.hex /usr/bin/avr-size -A /tmp/arduino_build_989748/Blink.ino.elf Sketch uses 3924 bytes (13%) of program storage space. Maximum is 28672 bytes. Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes. ``` --- ## Upload: Arduino Console .center[Im nächsten Schritt auf *Upload* (▶) klicken um den Code auf den Mikrocontroller zu spielen! Was passiert nun in der Console?] --- ## Arduino IDE build process? - Arduino Sketch (**.ino*) - Pre-Processing - C/C++ Code (**.cpp*) - Compile (avr-gcc) - Object files (**.o*) - Linker (avr-ld) - ELF file (**.elf*) - ELF Extracting (avr-objcopy) - Binary files (**.hex*) - Upload (avrdude) --- ## Build process In den temporären Datein können die verschiedenen Datein vom *Build process* angesehen werden. - Windows: *\AppData\Local\Temp\arduino_build_number* - OS X: */tmp/arduino_build_number** - Linux: */tmp/arduino_build_number* --- ## PWM Um die LED nicht nur ein- und auszuschalten kann mit der Pulsweitenmodulation (PWM) die LED *stufenweise* geschalten werden. .center[![PWM](pwm.gif)] .footnote[ [Bildquelle: Arduino CC PWM Tutorial](https://www.arduino.cc/en/Tutorial/Foundations/PWM) ] --- ## analogeWrite(pin, value) Für die PWM wird in der Arduino IDE die Funktion **analogWrite(pin, value)** verwendet. ``` c void loop(){ for(int i = 0; i < 255; i++){ analogWrite(11, i); } } ``` --- ## Serial Um zwischen Computer und Arduino zu kommunizieren wird *Serial* verwendet. Dazu muss im **void setup()** die Funktion **Serial.begin(speed)** aufgerufen. *speed* sind Bits/Sekunde oder auch Baud bzw. Baudrate genannt. Im **loop()** wird mit **Serial.available()** nach neuen Daten gefragt und mit **Serial.read()** ausgelesen. Nun kann mit dem Serial Monitor die LED ein und ausgeschalten werden. ``` c void setup() { Serial.begin(115200); pinMode(11, OUTPU); } void loop() { if(Serial.available()){ int value = Serial.read(); if(value == "1"){ digitalWrite(11,HIGH); } else if (value == 0){ digitalWrite(11,LOW); } } } ``` ## echo Baudrate