1 / 64

Arduino 201 Class

Arduino 201 Class. For those who want to learn more about the Arduino. Version 2.2. About Me. Objectives. WARNING: WORK IN PROGRESS. Introductions. WHAT IS AN ARDUINO COMPATIBLE?. Arduino Compatibility. Other Arduinos And Compatibles. Circuit Playground Express. Adafruit Flora.

jake
Download Presentation

Arduino 201 Class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arduino 201 Class For those who want to learn more about the Arduino Version 2.2

  2. About Me

  3. Objectives

  4. WARNING: WORK IN PROGRESS

  5. Introductions

  6. WHAT IS AN ARDUINO COMPATIBLE?

  7. Arduino Compatibility

  8. Other Arduinos And Compatibles Circuit Playground Express Adafruit Flora Adafruit Gemma (also LilyPad) Arduino Tiny (also Atom X1) Arduino Nano Adafruit Huzzah Feather Arduino Pro Mini Sparkfun Uno clone

  9. Espressif ESP32/ESP8266 https://www.espressif.com/en/products/hardware https://www.espressif.com/en/products/hardware/esp32/overview https://www.espressif.com/en/products/hardware/esp8266ex/overview

  10. Circuit Playground Express https://www.adafruit.com/product/3333 https://learn.adafruit.com/makecode

  11. Wearables Gemma Flora

  12. More Mega Than Mega Adafruit Grand Central STM32 There are quite a few boards out there that are faster, have more I/O, more math capabilities, more power capabilities, more rugged, etc than the Arduinos. The STM32 line has many options and form factors, and are designed more for real production / commercial usage. The Grand Central has a 120MHz Cortex M4 with floating point support, more ADCs, many more PWM outputs. Both have built in AES256 encryption engines and real random number generators https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html https://www.adafruit.com/product/4064

  13. Arduino vs Raspberry Pi/Beagle/etc

  14. OBJECT ORIENTED PROGRAMMING

  15. OO Overview

  16. OO advantages

  17. Object Oriented Concepts

  18. Example: LED dimming class // Declaration class DimmableLed { // Access specifier private: int pin; int currentLevel; void updateLed(); public: const int minLevel = 0; const int maxLevel = 255; Led(int pwmPin); void on(); void off(); void setLevel(int level); int getLevel(); }; // Constructor DimmableLed::DimmableLed(int pwmPin) { pin = pwmPin; currentLevel = 0; } void DimmableLed::updateLed() { Serial.print("LED updated to "); Serial.println(currentLevel); analogWrite(pin, currentLevel); } void DimmableLed::on() { currentLevel = maxLevel; updateLed(); } void DimmableLed::off() { currentLevel = minLevel; updateLed(); } void DimmableLed::setLevel(int level) { currentLevel = level; updateLed(); } int DimmableLed::getLevel() { return currentLevel; }

  19. Using DimmableLed // Global variables const int PWMPIN=9; DimmableLed myLed(PWMPIN); void setup() { } void loop() { myLed.on(); delay(100); myLed.off(); delay(100); for(int x = myLed.minLevel; x <= myLed.maxLevel; x+=10) { myLed.setLevel(x); delay(100); } myLed.off(); }

  20. OPTIONAL: OOP Project

  21. DEVICES AND COMMUNICATION

  22. Devices

  23. TTL connections

  24. Serial connections https://www.youtube.com/watch?v=IyGwvGzrqp8

  25. I2C / SPI

  26. CANBUS and DMX512

  27. LIBRARIES

  28. Libraries

  29. Popular Libraries https://www.arduino.cc/en/reference/libraries https://blog.adafruit.com/2019/03/16/top-10-arduino-library-downloads-arduino-arduinolibs-arduino-arduinod19/

  30. Creating your own library https://www.arduino.cc/en/Hacking/libraryTutorial https://github.com/arduino/Arduino/wiki/Library-Manager-FAQ https://www.youtube.com/watch?v=fE3Dw0slhIc

  31. OPTIONAL: Use a library? We can optionally write a program demonstrating usage of an existing library to output some content, or go on to the next topic, multitasking https://github.com/contrem/arduino-timer https://github.com/arduino-libraries/Arduino_JSON/ https://github.com/thijse/Arduino-Log/ https://github.com/mmurdoch/arduinounit

  32. “Multitasking”

  33. “Multitasking” With a single processor with a single core, only one thing can truly be running at a time, but we can task switch to get what we want done. There are several ways of doing this. OPTIONAL: This topic has a lot of slides, and optionally we can go into them in detail or go over them quickly

  34. Doing Multiple Things, Done Wrong void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } This is the standard Arduino “Blink” example. It’s fine for beginners, but… delay() is a blocking function. Blocking functions prevent a program from doing anything else until that particular task has completed. If you need multiple tasks to occur at the same time, you simply cannot use delay(). https://randomnerdtutorials.com/why-you-shouldnt-always-use-the-arduino-delay-function/

  35. Multitasking with functions in loop() The most straightforward way to multitask is to have checks for what “threads” need attention in loop and process them with each iteration. It’s best to break each piece into a separate function to make the code easier to read and maintain. void loop() { if(checkInputPins()) { handleInputPins(); } if(checkBluetooth()) { handleBluetooth(); } updateProgress(); if(checkLEDStatus()){ updateLEDs(); } }

  36. Level Up: Multitasking with OO Rather than using functions, define an update() method for your classes and call them in turn Void loop() { // We have an array that holds all of our input pin objects. // Iterate through them and let them update for(int x=0; x<MAX_INPUT_PINS; X++) { inputPins[x].update(); } bluetoothHandler.update(); progressBar.update(); // We also have an array of objects controlling LEDs // Iterate through them and let them update for(int x=0; x<MAX_LEDS; X++) { leds[x].update(); }

  37. Multitasking Using Time Periods With this technique, you keep track of the last time you did something, and in each loop iteration you check if it’s time to do it again (hint: This can be incorporated into the previous two ways too). This is a very efficient technique because very little time and memory is spent figuring out whether it’s time to update something or not. # Global variables unsigned long previousMillisInputPins = 0; unsigned long previousMillisProgress = 0; unsigned long currentMillis; … void loop() { currentMillis = millis(); if(currentMillis - previousMillisInputPins >= INPUT_FREQ_MILLIS) { handleInputPins(); previousMillisInputPins = currentMillis; } if(currentMillis - previousMillisProgress >= PROGRESS_FREQ_MILLIS) { updateProgress(); previousMillisProgress = currentMillis; } }

  38. Multitasking Using Time Periods

  39. Multitasking Using Interrupts https://learn.adafruit.com/multi-tasking-the-arduino-part-2/what-is-an-interrupt

  40. Timer Interrupts

  41. External Input Interrupts https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

  42. Doing Small Chunks Of Your Task https://learn.adafruit.com/multi-tasking-the-arduino-part-3/deconstructing-the-loop

  43. Fading An LED With Interrupts void updateLED(unsigned long thisMillis) { // is it time to update yet? if not, nothing happens if (thisMillis - previousFadeMillis >= fadeInterval) { if (fadeDirection == UP) { fadeValue = fadeValue + fadeIncrement; if (fadeValue >= maxPWM) { fadeValue = maxPWM; fadeDirection = DOWN; } } else { //if we aren't going up, we're going down fadeValue = fadeValue - fadeIncrement; if (fadeValue <= minPWM) { fadeValue = minPWM; fadeDirection = UP; } } analogWrite(pwmLED, fadeValue); previousFadeMillis = thisMillis; } } https://www.baldengineer.com/fading-led-analogwrite-millis-example.html

  44. INTERNET OF THINGS (IoT)

  45. What is IoT

  46. IoT Communication

  47. More Reliable Communication http://mqtt.org/https://io.adafruit.com/https://cloud.google.com/solutions/iot/ https://docs.aws.amazon.com/iot/https://mosquitto.org/

  48. The Dark Side of IoT

  49. Other Development Environments

More Related