1 / 96

Arduino 201 Class

Arduino 201 Class. For those who want to learn more about the Arduino. Version 2.0. About Me. Objectives. WARNING: WORK IN PROGRESS. WHAT IS AN ARDUINO COMPATIBLE?. Arduino Compatibility. Espressif ESP32/ESP8266. https://www.espressif.com/en/products/hardware

jlilley
Télécharger la présentation

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.0

  2. About Me

  3. Objectives

  4. WARNING: WORK IN PROGRESS

  5. WHAT IS AN ARDUINO COMPATIBLE?

  6. Arduino Compatibility

  7. 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

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

  9. Wearables Gemma Flora

  10. 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

  11. Arduino vs Raspberry Pi/Beagle/etc

  12. OBJECT ORIENTED PROGRAMMING

  13. OO Overview

  14. OO advantages

  15. Object Oriented Concepts

  16. 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::Led(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; }

  17. 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(); }

  18. OPTIONAL: OOP Project

  19. DEVICES AND COMMUNICATION

  20. Devices

  21. TTL connections

  22. Serial connections

  23. I2C / SPI

  24. CANBUS and DMX512

  25. LIBRARIES

  26. Libraries

  27. Popular Libraries https://www.arduino.cc/en/reference/libraries

  28. 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

  29. 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

  30. “Multitasking”

  31. “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

  32. 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/

  33. 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(); } }

  34. 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(); }

  35. 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; } }

  36. Multitasking Using Time Periods

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

  38. Timer Interrupts

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

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

  41. 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

  42. INTERNET OF THINGS (IoT)

  43. What is IoT

  44. IoT Communication

  45. 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/

  46. The Dark Side of IoT

  47. Other Development Environments

  48. The Need For Other Choices

  49. Visual Programming Without Code https://learn.sparkfun.com/tutorials/alternative-arduino-interfaces/all https://www.microsoft.com/en-us/makecode

  50. Alternate IDEs There are a few but for me Sloeber plugin for Eclipse the best

More Related